]>
Commit | Line | Data |
---|---|---|
923072b8 FG |
1 | // compile-flags: -Z unstable-options |
2 | ||
3 | #![crate_type = "lib"] | |
f2b60f7d | 4 | #![feature(rustc_attrs)] |
923072b8 FG |
5 | #![feature(rustc_private)] |
6 | #![deny(rustc::untranslatable_diagnostic)] | |
7 | #![deny(rustc::diagnostic_outside_of_impl)] | |
8 | ||
9 | extern crate rustc_errors; | |
10 | extern crate rustc_macros; | |
11 | extern crate rustc_session; | |
12 | extern crate rustc_span; | |
13 | ||
f2b60f7d FG |
14 | use rustc_errors::{ |
15 | AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent | |
16 | }; | |
923072b8 | 17 | use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; |
f2b60f7d | 18 | use rustc_session::SessionDiagnostic; |
923072b8 FG |
19 | use rustc_span::Span; |
20 | ||
21 | #[derive(SessionDiagnostic)] | |
f2b60f7d | 22 | #[diag(parser::expect_path)] |
923072b8 FG |
23 | struct DeriveSessionDiagnostic { |
24 | #[primary_span] | |
25 | span: Span, | |
26 | } | |
27 | ||
28 | #[derive(SessionSubdiagnostic)] | |
064997fb | 29 | #[note(parser::add_paren)] |
923072b8 FG |
30 | struct Note { |
31 | #[primary_span] | |
32 | span: Span, | |
33 | } | |
34 | ||
35 | pub struct UntranslatableInSessionDiagnostic; | |
36 | ||
37 | impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic { | |
f2b60f7d FG |
38 | fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { |
39 | handler.struct_err("untranslatable diagnostic") | |
923072b8 FG |
40 | //~^ ERROR diagnostics should be created using translatable messages |
41 | } | |
42 | } | |
43 | ||
44 | pub struct TranslatableInSessionDiagnostic; | |
45 | ||
46 | impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic { | |
f2b60f7d FG |
47 | fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { |
48 | handler.struct_err(fluent::parser::expect_path) | |
923072b8 FG |
49 | } |
50 | } | |
51 | ||
52 | pub struct UntranslatableInAddSubdiagnostic; | |
53 | ||
54 | impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic { | |
55 | fn add_to_diagnostic(self, diag: &mut Diagnostic) { | |
56 | diag.note("untranslatable diagnostic"); | |
57 | //~^ ERROR diagnostics should be created using translatable messages | |
58 | } | |
59 | } | |
60 | ||
61 | pub struct TranslatableInAddSubdiagnostic; | |
62 | ||
63 | impl AddSubdiagnostic for TranslatableInAddSubdiagnostic { | |
64 | fn add_to_diagnostic(self, diag: &mut Diagnostic) { | |
65 | diag.note(fluent::typeck::note); | |
66 | } | |
67 | } | |
68 | ||
f2b60f7d FG |
69 | pub fn make_diagnostics<'a>(handler: &'a Handler) { |
70 | let _diag = handler.struct_err(fluent::parser::expect_path); | |
923072b8 FG |
71 | //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls |
72 | ||
f2b60f7d | 73 | let _diag = handler.struct_err("untranslatable diagnostic"); |
923072b8 FG |
74 | //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls |
75 | //~^^ ERROR diagnostics should be created using translatable messages | |
76 | } | |
f2b60f7d FG |
77 | |
78 | // Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted. | |
79 | ||
80 | #[rustc_lint_diagnostics] | |
81 | pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) { | |
82 | let _diag = handler.struct_err("untranslatable diagnostic"); // okay! | |
83 | } |