]> git.proxmox.com Git - rustc.git/blame - src/test/ui-fulldeps/internal-lints/diagnostics.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / src / test / ui-fulldeps / internal-lints / diagnostics.rs
CommitLineData
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
9extern crate rustc_errors;
10extern crate rustc_macros;
11extern crate rustc_session;
12extern crate rustc_span;
13
f2b60f7d
FG
14use rustc_errors::{
15 AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent
16};
923072b8 17use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
f2b60f7d 18use rustc_session::SessionDiagnostic;
923072b8
FG
19use rustc_span::Span;
20
21#[derive(SessionDiagnostic)]
f2b60f7d 22#[diag(parser::expect_path)]
923072b8
FG
23struct DeriveSessionDiagnostic {
24 #[primary_span]
25 span: Span,
26}
27
28#[derive(SessionSubdiagnostic)]
064997fb 29#[note(parser::add_paren)]
923072b8
FG
30struct Note {
31 #[primary_span]
32 span: Span,
33}
34
35pub struct UntranslatableInSessionDiagnostic;
36
37impl<'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
44pub struct TranslatableInSessionDiagnostic;
45
46impl<'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
52pub struct UntranslatableInAddSubdiagnostic;
53
54impl 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
61pub struct TranslatableInAddSubdiagnostic;
62
63impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
64 fn add_to_diagnostic(self, diag: &mut Diagnostic) {
65 diag.note(fluent::typeck::note);
66 }
67}
68
f2b60f7d
FG
69pub 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]
81pub fn skipped_because_of_annotation<'a>(handler: &'a Handler) {
82 let _diag = handler.struct_err("untranslatable diagnostic"); // okay!
83}