@@ -30,26 +30,27 @@ impl<'a> DiagnosticDerive<'a> {
3030 pub ( crate ) fn into_tokens ( self ) -> TokenStream {
3131 let DiagnosticDerive { mut structure, mut builder } = self ;
3232
33- let slugs = RefCell :: new ( Vec :: new ( ) ) ;
3433 let implementation = builder. each_variant ( & mut structure, |mut builder, variant| {
35- let preamble = builder. preamble ( variant) ;
36- let body = builder. body ( variant) ;
37-
3834 let diag = & builder. parent . diag ;
3935 let DiagnosticDeriveKind :: Diagnostic { handler } = & builder. parent . kind else {
36+ eprintln ! ( "BUG: DiagnosticDeriveKind::Diagnostic expected" ) ;
4037 unreachable ! ( )
4138 } ;
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" )
4546 . help (
4647 "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 .. \" )] ",
4849 )
4950 . emit ( ) ;
5051 return DiagnosticDeriveError :: ErrorHandled . to_compile_error ( ) ;
5152 }
52- Some ( slug)
53+ ( Some ( slug) , None )
5354 if let Some ( Mismatch { slug_name, crate_name, slug_prefix } ) =
5455 Mismatch :: check ( slug) =>
5556 {
@@ -59,12 +60,19 @@ impl<'a> DiagnosticDerive<'a> {
5960 . emit ( ) ;
6061 return DiagnosticDeriveError :: ErrorHandled . to_compile_error ( ) ;
6162 }
62- Some ( slug) => {
63- slugs. borrow_mut ( ) . push ( slug. clone ( ) ) ;
63+ ( Some ( slug) , None ) => {
6464 quote ! {
6565 let mut #diag = #handler. struct_diagnostic( crate :: fluent_generated:: #slug) ;
6666 }
6767 }
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+ }
6876 } ;
6977
7078 let formatting_init = & builder. formatting_init ;
@@ -77,9 +85,11 @@ impl<'a> DiagnosticDerive<'a> {
7785 }
7886 } ) ;
7987
80- let DiagnosticDeriveKind :: Diagnostic { handler } = & builder. kind else { unreachable ! ( ) } ;
88+ let DiagnosticDeriveKind :: Diagnostic { handler } = & builder. kind else {
89+ unreachable ! ( ) ;
90+ } ;
8191
82- let mut imp = structure. gen_impl ( quote ! {
92+ let imp = structure. gen_impl ( quote ! {
8393 gen impl <' __diagnostic_handler_sess, G >
8494 rustc_errors:: IntoDiagnostic <' __diagnostic_handler_sess, G >
8595 for @Self
@@ -96,9 +106,6 @@ impl<'a> DiagnosticDerive<'a> {
96106 }
97107 }
98108 } ) ;
99- for test in slugs. borrow ( ) . iter ( ) . map ( |s| generate_test ( s, & structure) ) {
100- imp. extend ( test) ;
101- }
102109 imp
103110 }
104111}
0 commit comments