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
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(self, diag: &mut Diagnostic) {
56 diag.note("untranslatable diagnostic");
57 //~^ ERROR diagnostics should be created using translatable messages
61 pub struct TranslatableInAddToDiagnostic;
63 impl AddToDiagnostic for TranslatableInAddToDiagnostic {
64 fn add_to_diagnostic(self, diag: &mut Diagnostic) {
65 diag.note(fluent::compiletest::note);
69 pub fn make_diagnostics<'a>(handler: &'a Handler) {
70 let _diag = handler.struct_err(fluent::compiletest::example);
71 //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
73 let _diag = handler.struct_err("untranslatable diagnostic");
74 //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
75 //~^^ ERROR diagnostics should be created using translatable messages
78 // Check that `rustc_lint_diagnostics`-annotated functions aren't themselves linted.
80 #[rustc_lint_diagnostics]
81 pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) {
82 let _diag = handler.struct_err("untranslatable diagnostic"); // okay!