@@ -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 ;
@@ -66,9 +65,6 @@ pub(crate) struct DiagnosticDeriveVariantBuilder<'parent> {
66
65
67
66
/// Attributes on the variant.
68
67
pub attrs : HashMap < String , LitStr > ,
69
-
70
- /// fields for bidnings in the variant.
71
- pub fields : FieldMap ,
72
68
}
73
69
74
70
impl < ' a > HasFieldMap for DiagnosticDeriveVariantBuilder < ' a > {
@@ -121,7 +117,6 @@ impl DiagnosticDeriveBuilder {
121
117
code : None ,
122
118
label : None ,
123
119
attrs : HashMap :: new ( ) ,
124
- fields : HashMap :: new ( ) ,
125
120
} ;
126
121
f ( builder, variant)
127
122
} ) ;
@@ -140,9 +135,6 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
140
135
pub fn preamble ( & mut self , variant : & VariantInfo < ' _ > ) -> TokenStream {
141
136
let ast = variant. ast ( ) ;
142
137
let attrs = & ast. attrs ;
143
- for binding in variant. bindings ( ) . iter ( ) . filter ( |bi| should_generate_set_arg ( bi. ast ( ) ) ) {
144
- self . generate_binding_for_attr ( binding) ;
145
- }
146
138
147
139
let preamble = attrs. iter ( ) . map ( |attr| {
148
140
self . generate_structure_code_for_attr ( attr) . unwrap_or_else ( |v| v. to_compile_error ( ) )
@@ -193,7 +185,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
193
185
SubdiagnosticKind :: MultipartSuggestion { .. } => unreachable ! ( ) ,
194
186
} ) ;
195
187
196
- Ok ( Some ( ( subdiag. kind , slug, subdiag. no_span , subdiag. text . map ( |t| t. value ( ) ) ) ) )
188
+ Ok ( Some ( ( subdiag. kind , slug, subdiag. no_span , subdiag. raw_label . map ( |t| t. value ( ) ) ) ) )
197
189
}
198
190
199
191
/// Establishes state in the `DiagnosticDeriveBuilder` resulting from the struct
@@ -283,7 +275,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
283
275
return Ok ( ( ) ) ;
284
276
} ;
285
277
286
- if path. is_ident ( "text" ) || path . is_ident ( " label") {
278
+ if path. is_ident ( "label" ) {
287
279
let value = nested. parse :: < syn:: LitStr > ( ) ?;
288
280
self . label . set_once ( value, path. span ( ) . unwrap ( ) ) ;
289
281
} else if path. is_ident ( "code" ) {
@@ -314,15 +306,15 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
314
306
return Ok ( tokens) ;
315
307
}
316
308
317
- let Some ( ( subdiag, slug, _no_span, text ) ) = self . parse_subdiag_attribute ( attr) ? else {
309
+ let Some ( ( subdiag, slug, _no_span, raw_label ) ) = self . parse_subdiag_attribute ( attr) ? else {
318
310
// Some attributes aren't errors - like documentation comments - but also aren't
319
311
// subdiagnostics.
320
312
return Ok ( quote ! { } ) ;
321
313
} ;
322
314
let fn_ident = format_ident ! ( "{}" , subdiag) ;
323
315
match subdiag {
324
316
SubdiagnosticKind :: Note | SubdiagnosticKind :: Help | SubdiagnosticKind :: Warn => {
325
- Ok ( self . add_subdiagnostic ( & fn_ident, slug, text ) )
317
+ Ok ( self . add_subdiagnostic ( & fn_ident, slug, raw_label ) )
326
318
}
327
319
SubdiagnosticKind :: Label | SubdiagnosticKind :: Suggestion { .. } => {
328
320
throw_invalid_attr ! ( attr, |diag| diag
@@ -349,16 +341,6 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
349
341
}
350
342
}
351
343
352
- fn generate_binding_for_attr ( & mut self , binding_info : & BindingInfo < ' _ > ) {
353
- let field = binding_info. ast ( ) ;
354
- let mut field_binding = binding_info. binding . clone ( ) ;
355
- field_binding. set_span ( field. ty . span ( ) ) ;
356
-
357
- let ident = field. ident . as_ref ( ) . unwrap ( ) ;
358
- let ident = format_ident ! ( "{}" , ident) ; // strip `r#` prefix, if present
359
- self . fields . insert ( ident. to_string ( ) , field_binding. into_token_stream ( ) ) ;
360
- }
361
-
362
344
fn generate_field_attrs_code ( & mut self , binding_info : & BindingInfo < ' _ > ) -> TokenStream {
363
345
let field = binding_info. ast ( ) ;
364
346
let field_binding = & binding_info. binding ;
@@ -474,7 +456,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
474
456
_ => ( ) ,
475
457
}
476
458
477
- let Some ( ( subdiag, slug, _no_span, text ) ) = self . parse_subdiag_attribute ( attr) ? else {
459
+ let Some ( ( subdiag, slug, _no_span, raw_label ) ) = self . parse_subdiag_attribute ( attr) ? else {
478
460
// Some attributes aren't errors - like documentation comments - but also aren't
479
461
// subdiagnostics.
480
462
return Ok ( quote ! { } ) ;
@@ -483,18 +465,18 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
483
465
match subdiag {
484
466
SubdiagnosticKind :: Label => {
485
467
report_error_if_not_applied_to_span ( attr, & info) ?;
486
- Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, text ) )
468
+ Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, raw_label ) )
487
469
}
488
470
SubdiagnosticKind :: Note | SubdiagnosticKind :: Help | SubdiagnosticKind :: Warn => {
489
471
let inner = info. ty . inner_type ( ) ;
490
472
if type_matches_path ( inner, & [ "rustc_span" , "Span" ] )
491
473
|| type_matches_path ( inner, & [ "rustc_span" , "MultiSpan" ] )
492
474
{
493
- Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, text ) )
475
+ Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, raw_label ) )
494
476
} else if type_is_unit ( inner)
495
477
|| ( matches ! ( info. ty, FieldInnerTy :: Plain ( _) ) && type_is_bool ( inner) )
496
478
{
497
- Ok ( self . add_subdiagnostic ( & fn_ident, slug, text ) )
479
+ Ok ( self . add_subdiagnostic ( & fn_ident, slug, raw_label ) )
498
480
} else {
499
481
report_type_error ( attr, "`Span`, `MultiSpan`, `bool` or `()`" ) ?
500
482
}
@@ -525,10 +507,9 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
525
507
. unwrap_or_else ( || quote ! { rustc_errors:: Applicability :: Unspecified } ) ;
526
508
let style = suggestion_kind. to_suggestion_style ( ) ;
527
509
528
- let suggestion_label = if let Some ( text) = text {
529
- //let text = format_for_variables(&text, &self.fields);
510
+ let suggestion_label = if let Some ( raw_label) = raw_label {
530
511
quote ! {
531
- #text
512
+ #raw_label
532
513
}
533
514
} else {
534
515
quote ! {
@@ -558,24 +539,23 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
558
539
field_binding : TokenStream ,
559
540
kind : & Ident ,
560
541
fluent_attr_identifier : Path ,
561
- text : Option < String > ,
542
+ raw_label : Option < String > ,
562
543
) -> TokenStream {
563
544
let diag = & self . parent . diag ;
564
545
let fn_name = format_ident ! ( "span_{}" , kind) ;
565
- if let Some ( text) = text {
566
- //let text = format_for_variables(&text, &self.fields);
546
+ if let Some ( raw_label) = raw_label {
567
547
return quote ! {
568
548
#diag. #fn_name(
569
549
#field_binding,
570
- #text
550
+ #raw_label
571
551
) ;
572
552
} ;
573
553
}
574
- if let Some ( text ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
554
+ if let Some ( raw_label ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
575
555
quote ! {
576
556
#diag. #fn_name(
577
557
#field_binding,
578
- #text
558
+ #raw_label
579
559
) ;
580
560
}
581
561
} else {
@@ -594,22 +574,17 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
594
574
& self ,
595
575
kind : & Ident ,
596
576
fluent_attr_identifier : Path ,
597
- text : Option < String > ,
577
+ raw_label : Option < String > ,
598
578
) -> TokenStream {
599
579
let diag = & self . parent . diag ;
600
- // eprintln!(
601
- // "add_subdiagnostic fluent_attr_identifier: {:?} text: {:?}",
602
- // fluent_attr_identifier, text
603
- // );
604
- if let Some ( text) = text {
605
- //let text = format_for_variables(&text, &self.fields);
580
+ if let Some ( raw_label) = raw_label {
606
581
return quote ! {
607
- #diag. #kind( #text ) ;
582
+ #diag. #kind( #raw_label ) ;
608
583
} ;
609
584
}
610
- if let Some ( text ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
585
+ if let Some ( raw_label ) = self . get_attr ( kind. to_string ( ) . as_str ( ) ) {
611
586
quote ! {
612
- #diag. #kind( #text ) ;
587
+ #diag. #kind( #raw_label ) ;
613
588
}
614
589
} else {
615
590
quote ! {
@@ -677,7 +652,6 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
677
652
678
653
fn get_attr ( & self , key : & str ) -> Option < TokenStream > {
679
654
self . attrs . get ( key) . map ( |val| {
680
- //let text = format_for_variables(&val.value(), &self.fields);
681
655
let text = & val. value ( ) ;
682
656
quote ! {
683
657
#text
0 commit comments