]> git.lizzy.rs Git - rust.git/blob - src/test/ui-fulldeps/internal-lints/diagnostics.rs
Rollup merge of #98428 - davidtwco:translation-derive-typed-identifiers, r=oli-obk
[rust.git] / src / test / ui-fulldeps / internal-lints / diagnostics.rs
1 // compile-flags: -Z unstable-options
2
3 #![crate_type = "lib"]
4 #![feature(rustc_private)]
5 #![deny(rustc::untranslatable_diagnostic)]
6 #![deny(rustc::diagnostic_outside_of_impl)]
7
8 extern crate rustc_errors;
9 extern crate rustc_macros;
10 extern crate rustc_session;
11 extern crate rustc_span;
12
13 use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent};
14 use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
15 use rustc_session::{parse::ParseSess, SessionDiagnostic};
16 use rustc_span::Span;
17
18 #[derive(SessionDiagnostic)]
19 #[error(parser::expect_path)]
20 struct DeriveSessionDiagnostic {
21     #[primary_span]
22     span: Span,
23 }
24
25 #[derive(SessionSubdiagnostic)]
26 #[note(parser::add_paren)]
27 struct Note {
28     #[primary_span]
29     span: Span,
30 }
31
32 pub struct UntranslatableInSessionDiagnostic;
33
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
38     }
39 }
40
41 pub struct TranslatableInSessionDiagnostic;
42
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)
46     }
47 }
48
49 pub struct UntranslatableInAddSubdiagnostic;
50
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
55     }
56 }
57
58 pub struct TranslatableInAddSubdiagnostic;
59
60 impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
61     fn add_to_diagnostic(self, diag: &mut Diagnostic) {
62         diag.note(fluent::typeck::note);
63     }
64 }
65
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
69
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
73 }