@@ -30,26 +30,27 @@ impl<'a> DiagnosticDerive<'a> {
30
30
pub ( crate ) fn into_tokens ( self ) -> TokenStream {
31
31
let DiagnosticDerive { mut structure, mut builder } = self ;
32
32
33
- let slugs = RefCell :: new ( Vec :: new ( ) ) ;
34
33
let implementation = builder. each_variant ( & mut structure, |mut builder, variant| {
35
- let preamble = builder. preamble ( variant) ;
36
- let body = builder. body ( variant) ;
37
-
38
34
let diag = & builder. parent . diag ;
39
35
let DiagnosticDeriveKind :: Diagnostic { handler } = & builder. parent . kind else {
36
+ eprintln ! ( "BUG: DiagnosticDeriveKind::Diagnostic expected" ) ;
40
37
unreachable ! ( )
41
38
} ;
42
- let init = match builder. slug . value_ref ( ) {
43
- None => {
44
- span_err ( builder. span , "diagnostic slug not specified" )
39
+
40
+ let preamble = builder. preamble ( variant) ;
41
+ let body = builder. body ( variant) ;
42
+
43
+ let init = match ( builder. slug . value_ref ( ) , builder. label . value_ref ( ) ) {
44
+ ( None , None ) => {
45
+ span_err ( builder. span , "diagnostic slug or label is not specified" )
45
46
. help (
46
47
"specify the slug as the first argument to the `#[diag(...)]` \
47
- attribute, such as `#[diag(hir_analysis_example_error)]`",
48
+ attribute, such as `#[diag(hir_analysis_example_error)]`, or use format #[diag(label = \" the message .. \" )] ",
48
49
)
49
50
. emit ( ) ;
50
51
return DiagnosticDeriveError :: ErrorHandled . to_compile_error ( ) ;
51
52
}
52
- Some ( slug)
53
+ ( Some ( slug) , None )
53
54
if let Some ( Mismatch { slug_name, crate_name, slug_prefix } ) =
54
55
Mismatch :: check ( slug) =>
55
56
{
@@ -59,12 +60,19 @@ impl<'a> DiagnosticDerive<'a> {
59
60
. emit ( ) ;
60
61
return DiagnosticDeriveError :: ErrorHandled . to_compile_error ( ) ;
61
62
}
62
- Some ( slug) => {
63
- slugs. borrow_mut ( ) . push ( slug. clone ( ) ) ;
63
+ ( Some ( slug) , None ) => {
64
64
quote ! {
65
65
let mut #diag = #handler. struct_diagnostic( crate :: fluent_generated:: #slug) ;
66
66
}
67
67
}
68
+ ( None , Some ( text) ) => {
69
+ quote ! {
70
+ let mut #diag = #handler. struct_diagnostic( DiagnosticMessage :: Str ( #text. into( ) ) ) ;
71
+ }
72
+ }
73
+ ( Some ( _slug) , Some ( _text) ) => {
74
+ unreachable ! ( "BUG: slug and text specified" ) ;
75
+ }
68
76
} ;
69
77
70
78
let formatting_init = & builder. formatting_init ;
@@ -77,9 +85,11 @@ impl<'a> DiagnosticDerive<'a> {
77
85
}
78
86
} ) ;
79
87
80
- let DiagnosticDeriveKind :: Diagnostic { handler } = & builder. kind else { unreachable ! ( ) } ;
88
+ let DiagnosticDeriveKind :: Diagnostic { handler } = & builder. kind else {
89
+ unreachable ! ( ) ;
90
+ } ;
81
91
82
- let mut imp = structure. gen_impl ( quote ! {
92
+ let imp = structure. gen_impl ( quote ! {
83
93
gen impl <' __diagnostic_handler_sess, G >
84
94
rustc_errors:: IntoDiagnostic <' __diagnostic_handler_sess, G >
85
95
for @Self
@@ -96,9 +106,6 @@ impl<'a> DiagnosticDerive<'a> {
96
106
}
97
107
}
98
108
} ) ;
99
- for test in slugs. borrow ( ) . iter ( ) . map ( |s| generate_test ( s, & structure) ) {
100
- imp. extend ( test) ;
101
- }
102
109
imp
103
110
}
104
111
}
0 commit comments