1 // compile-flags: -Z unstable-options
4 #![feature(rustc_attrs)]
5 #![feature(rustc_private)]
6 #![deny(rustc::untranslatable_diagnostic)]
7 #![deny(rustc::diagnostic_outside_of_impl)]
9 extern crate rustc_errors;
10 extern crate rustc_macros;
11 extern crate rustc_session;
12 extern crate rustc_span;
15 AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder,
16 ErrorGuaranteed, Handler, fluent, SubdiagnosticMessage,
18 use rustc_macros::{Diagnostic, Subdiagnostic};
22 #[diag(compiletest_example)]
23 struct DeriveDiagnostic {
28 #[derive(Subdiagnostic)]
29 #[note(compiletest_example)]
35 pub struct UntranslatableInIntoDiagnostic;
37 impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic {
38 fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
39 handler.struct_err("untranslatable diagnostic")
40 //~^ ERROR diagnostics should be created using translatable messages
44 pub struct TranslatableInIntoDiagnostic;
46 impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic {
47 fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
48 handler.struct_err(fluent::compiletest_example)
52 pub struct UntranslatableInAddToDiagnostic;
54 impl AddToDiagnostic for UntranslatableInAddToDiagnostic {
55 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
57 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
59 diag.note("untranslatable diagnostic");
60 //~^ ERROR diagnostics should be created using translatable messages
64 pub struct TranslatableInAddToDiagnostic;
66 impl AddToDiagnostic for TranslatableInAddToDiagnostic {
67 fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
69 F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
71 diag.note(fluent::note);
75 pub fn make_diagnostics<'a>(handler: &'a Handler) {
76 let _diag = handler.struct_err(fluent::compiletest_example);
77 //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
79 let _diag = handler.struct_err("untranslatable diagnostic");
80 //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
81 //~^^ ERROR diagnostics should be created using translatable messages
84 // Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted.
86 #[rustc_lint_diagnostics]
87 pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) {
88 let _diag = handler.struct_err("untranslatable diagnostic"); // okay!