1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// compile-flags: -Z unstable-options
#![crate_type = "lib"]
#![feature(rustc_private)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
extern crate rustc_errors;
extern crate rustc_macros;
extern crate rustc_session;
extern crate rustc_span;
use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent};
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
use rustc_session::{parse::ParseSess, SessionDiagnostic};
use rustc_span::Span;
#[derive(SessionDiagnostic)]
#[error(parser::expect_path)]
struct DeriveSessionDiagnostic {
#[primary_span]
span: Span,
}
#[derive(SessionSubdiagnostic)]
#[note(parser::add_paren)]
struct Note {
#[primary_span]
span: Span,
}
pub struct UntranslatableInSessionDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
sess.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages
}
}
pub struct TranslatableInSessionDiagnostic;
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
sess.struct_err(fluent::parser::expect_path)
}
}
pub struct UntranslatableInAddSubdiagnostic;
impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic {
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.note("untranslatable diagnostic");
//~^ ERROR diagnostics should be created using translatable messages
}
}
pub struct TranslatableInAddSubdiagnostic;
impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
diag.note(fluent::typeck::note);
}
}
pub fn make_diagnostics<'a>(sess: &'a ParseSess) {
let _diag = sess.struct_err(fluent::parser::expect_path);
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
let _diag = sess.struct_err("untranslatable diagnostic");
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages
}
|