@@ -4,14 +4,13 @@ use super::utils::{convert_to_litstr, SubdiagnosticVariant};
4
4
use crate :: diagnostics:: error:: {
5
5
span_err, throw_invalid_attr, throw_span_err, DiagnosticDeriveError ,
6
6
} ;
7
- //use crate::diagnostics::utils::format_for_variables;
8
7
use crate :: diagnostics:: utils:: {
9
8
build_field_mapping, is_doc_comment, report_error_if_not_applied_to_span, report_type_error,
10
9
should_generate_set_arg, type_is_bool, type_is_unit, type_matches_path, FieldInfo ,
11
10
FieldInnerTy , FieldMap , HasFieldMap , SetOnce , SpannedOption , SubdiagnosticKind ,
12
11
} ;
13
12
use proc_macro2:: { Ident , Span , TokenStream , TokenTree } ;
14
- use quote:: { format_ident, quote, quote_spanned, ToTokens } ;
13
+ use quote:: { format_ident, quote, quote_spanned} ;
15
14
use std:: collections:: HashMap ;
16
15
use syn:: MetaList ;
17
16
use syn:: Token ;
@@ -56,9 +55,6 @@ pub(crate) struct DiagnosticDeriveVariantBuilder {
56
55
57
56
/// Attributes on the variant.
58
57
pub attrs : HashMap < String , LitStr > ,
59
-
60
- /// fields for bidnings in the variant.
61
- pub fields : FieldMap ,
62
58
}
63
59
64
60
impl HasFieldMap for DiagnosticDeriveVariantBuilder {
@@ -111,7 +107,6 @@ impl DiagnosticDeriveKind {
111
107
code : None ,
112
108
label : None ,
113
109
attrs : HashMap :: new ( ) ,
114
- fields : HashMap :: new ( ) ,
115
110
} ;
116
111
f ( builder, variant)
117
112
} ) ;
@@ -130,9 +125,6 @@ impl DiagnosticDeriveVariantBuilder {
130
125
pub ( crate ) fn preamble ( & mut self , variant : & VariantInfo < ' _ > ) -> TokenStream {
131
126
let ast = variant. ast ( ) ;
132
127
let attrs = & ast. attrs ;
133
- for binding in variant. bindings ( ) . iter ( ) . filter ( |bi| should_generate_set_arg ( bi. ast ( ) ) ) {
134
- self . generate_binding_for_attr ( binding) ;
135
- }
136
128
137
129
let preamble = attrs. iter ( ) . map ( |attr| {
138
130
self . generate_structure_code_for_attr ( attr) . unwrap_or_else ( |v| v. to_compile_error ( ) )
@@ -183,7 +175,7 @@ impl DiagnosticDeriveVariantBuilder {
183
175
SubdiagnosticKind :: MultipartSuggestion { .. } => unreachable ! ( ) ,
184
176
} ) ;
185
177
186
- Ok ( Some ( ( subdiag. kind , slug, subdiag. no_span , subdiag. text . map ( |t| t. value ( ) ) ) ) )
178
+ Ok ( Some ( ( subdiag. kind , slug, subdiag. no_span , subdiag. raw_label . map ( |t| t. value ( ) ) ) ) )
187
179
}
188
180
189
181
/// Establishes state in the `DiagnosticDeriveBuilder` resulting from the struct
@@ -271,7 +263,7 @@ impl DiagnosticDeriveVariantBuilder {
271
263
return Ok ( ( ) ) ;
272
264
} ;
273
265
274
- if path. is_ident ( "text" ) || path . is_ident ( " label") {
266
+ if path. is_ident ( "label" ) {
275
267
let value = nested. parse :: < syn:: LitStr > ( ) ?;
276
268
self . label . set_once ( value, path. span ( ) . unwrap ( ) ) ;
277
269
} else if path. is_ident ( "code" ) {
@@ -302,15 +294,15 @@ impl DiagnosticDeriveVariantBuilder {
302
294
return Ok ( tokens) ;
303
295
}
304
296
305
- let Some ( ( subdiag, slug, _no_span, text ) ) = self . parse_subdiag_attribute ( attr) ? else {
297
+ let Some ( ( subdiag, slug, _no_span, raw_label ) ) = self . parse_subdiag_attribute ( attr) ? else {
306
298
// Some attributes aren't errors - like documentation comments - but also aren't
307
299
// subdiagnostics.
308
300
return Ok ( quote ! { } ) ;
309
301
} ;
310
302
let fn_ident = format_ident ! ( "{}" , subdiag) ;
311
303
match subdiag {
312
304
SubdiagnosticKind :: Note | SubdiagnosticKind :: Help | SubdiagnosticKind :: Warn => {
313
- Ok ( self . add_subdiagnostic ( & fn_ident, slug, text ) )
305
+ Ok ( self . add_subdiagnostic ( & fn_ident, slug, raw_label ) )
314
306
}
315
307
SubdiagnosticKind :: Label | SubdiagnosticKind :: Suggestion { .. } => {
316
308
throw_invalid_attr ! ( attr, |diag| diag
@@ -335,16 +327,6 @@ impl DiagnosticDeriveVariantBuilder {
335
327
}
336
328
}
337
329
338
- fn generate_binding_for_attr ( & mut self , binding_info : & BindingInfo < ' _ > ) {
339
- let field = binding_info. ast ( ) ;
340
- let mut field_binding = binding_info. binding . clone ( ) ;
341
- field_binding. set_span ( field. ty . span ( ) ) ;
342
-
343
- let ident = field. ident . as_ref ( ) . unwrap ( ) ;
344
- let ident = format_ident ! ( "{}" , ident) ; // strip `r#` prefix, if present
345
- self . fields . insert ( ident. to_string ( ) , field_binding. into_token_stream ( ) ) ;
346
- }
347
-
348
330
fn generate_field_attrs_code ( & mut self , binding_info : & BindingInfo < ' _ > ) -> TokenStream {
349
331
let field = binding_info. ast ( ) ;
350
332
let field_binding = & binding_info. binding ;
@@ -458,7 +440,7 @@ impl DiagnosticDeriveVariantBuilder {
458
440
_ => ( ) ,
459
441
}
460
442
461
- let Some ( ( subdiag, slug, _no_span, text ) ) = self . parse_subdiag_attribute ( attr) ? else {
443
+ let Some ( ( subdiag, slug, _no_span, raw_label ) ) = self . parse_subdiag_attribute ( attr) ? else {
462
444
// Some attributes aren't errors - like documentation comments - but also aren't
463
445
// subdiagnostics.
464
446
return Ok ( quote ! { } ) ;
@@ -467,18 +449,18 @@ impl DiagnosticDeriveVariantBuilder {
467
449
match subdiag {
468
450
SubdiagnosticKind :: Label => {
469
451
report_error_if_not_applied_to_span ( attr, & info) ?;
470
- Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, text ) )
452
+ Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, raw_label ) )
471
453
}
472
454
SubdiagnosticKind :: Note | SubdiagnosticKind :: Help | SubdiagnosticKind :: Warn => {
473
455
let inner = info. ty . inner_type ( ) ;
474
456
if type_matches_path ( inner, & [ "rustc_span" , "Span" ] )
475
457
|| type_matches_path ( inner, & [ "rustc_span" , "MultiSpan" ] )
476
458
{
477
- Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, text ) )
459
+ Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, raw_label ) )
478
460
} else if type_is_unit ( inner)
479
461
|| ( matches ! ( info. ty, FieldInnerTy :: Plain ( _) ) && type_is_bool ( inner) )
480
462
{
481
- Ok ( self . add_subdiagnostic ( & fn_ident, slug, text ) )
463
+ Ok ( self . add_subdiagnostic ( & fn_ident, slug, raw_label ) )
482
464
} else {
483
465
report_type_error ( attr, "`Span`, `MultiSpan`, `bool` or `()`" ) ?
484
466
}
@@ -509,10 +491,9 @@ impl DiagnosticDeriveVariantBuilder {
509
491
. unwrap_or_else ( || quote ! { rustc_errors:: Applicability :: Unspecified } ) ;
510
492
let style = suggestion_kind. to_suggestion_style ( ) ;
511
493
512
- let suggestion_label = if let Some ( text) = text {
513
- //let text = format_for_variables(&text, &self.fields);
494
+ let suggestion_label = if let Some ( raw_label) = raw_label {
514
495
quote ! {
515
- #text
496
+ #raw_label
516
497
}
517
498
} else {
518
499
quote ! {
@@ -542,23 +523,22 @@ impl DiagnosticDeriveVariantBuilder {
542
523
field_binding : TokenStream ,
543
524
kind : & Ident ,
544
525
fluent_attr_identifier : Path ,
545
- text : Option < String > ,
526
+ raw_label : Option < String > ,
546
527
) -> TokenStream {
547
528
let fn_name = format_ident ! ( "span_{}" , kind) ;
548
- if let Some ( text) = text {
549
- //let text = format_for_variables(&text, &self.fields);
529
+ if let Some ( raw_label) = raw_label {
550
530
return quote ! {
551
531
#diag. #fn_name(
552
532
#field_binding,
553
- #text
533
+ #raw_label
554
534
) ;
555
535
} ;
556
536
}
557
- if let Some ( text ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
537
+ if let Some ( raw_label ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
558
538
quote ! {
559
539
#diag. #fn_name(
560
540
#field_binding,
561
- #text
541
+ #raw_label
562
542
) ;
563
543
}
564
544
} else {
@@ -577,22 +557,17 @@ impl DiagnosticDeriveVariantBuilder {
577
557
& self ,
578
558
kind : & Ident ,
579
559
fluent_attr_identifier : Path ,
580
- text : Option < String > ,
560
+ raw_label : Option < String > ,
581
561
) -> TokenStream {
582
562
let diag = & self . parent . diag ;
583
- // eprintln!(
584
- // "add_subdiagnostic fluent_attr_identifier: {:?} text: {:?}",
585
- // fluent_attr_identifier, text
586
- // );
587
- if let Some ( text) = text {
588
- //let text = format_for_variables(&text, &self.fields);
563
+ if let Some ( raw_label) = raw_label {
589
564
return quote ! {
590
- #diag. #kind( #text ) ;
565
+ #diag. #kind( #raw_label ) ;
591
566
} ;
592
567
}
593
- if let Some ( text ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
568
+ if let Some ( raw_label ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
594
569
quote ! {
595
- #diag. #kind( #text ) ;
570
+ #diag. #kind( #raw_label ) ;
596
571
}
597
572
} else {
598
573
quote ! {
@@ -660,7 +635,6 @@ impl DiagnosticDeriveVariantBuilder {
660
635
661
636
fn get_attr ( & self , key : & str ) -> Option < TokenStream > {
662
637
self . attrs . get ( key) . map ( |val| {
663
- //let text = format_for_variables(&val.value(), &self.fields);
664
638
let text = & val. value ( ) ;
665
639
quote ! {
666
640
#text
0 commit comments