1 // compile-flags: -Z unstable-options
4 #![feature(rustc_private)]
5 #![deny(rustc::untranslatable_diagnostic)]
6 #![deny(rustc::diagnostic_outside_of_impl)]
8 extern crate rustc_errors;
9 extern crate rustc_macros;
10 extern crate rustc_session;
11 extern crate rustc_span;
13 use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent};
14 use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
15 use rustc_session::{parse::ParseSess, SessionDiagnostic};
18 #[derive(SessionDiagnostic)]
19 #[error(parser::expect_path)]
20 struct DeriveSessionDiagnostic {
25 #[derive(SessionSubdiagnostic)]
26 #[note(parser::add_paren)]
32 pub struct UntranslatableInSessionDiagnostic;
34 impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
35 fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
36 sess.struct_err("untranslatable diagnostic")
37 //~^ ERROR diagnostics should be created using translatable messages
41 pub struct TranslatableInSessionDiagnostic;
43 impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
44 fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
45 sess.struct_err(fluent::parser::expect_path)
49 pub struct UntranslatableInAddSubdiagnostic;
51 impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic {
52 fn add_to_diagnostic(self, diag: &mut Diagnostic) {
53 diag.note("untranslatable diagnostic");
54 //~^ ERROR diagnostics should be created using translatable messages
58 pub struct TranslatableInAddSubdiagnostic;
60 impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
61 fn add_to_diagnostic(self, diag: &mut Diagnostic) {
62 diag.note(fluent::typeck::note);
66 pub fn make_diagnostics<'a>(sess: &'a ParseSess) {
67 let _diag = sess.struct_err(fluent::parser::expect_path);
68 //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
70 let _diag = sess.struct_err("untranslatable diagnostic");
71 //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
72 //~^^ ERROR diagnostics should be created using translatable messages