@@ -4,14 +4,13 @@ use super::utils::{convert_to_litstr, SubdiagnosticVariant};
44use crate :: diagnostics:: error:: {
55 span_err, throw_invalid_attr, throw_span_err, DiagnosticDeriveError ,
66} ;
7- //use crate::diagnostics::utils::format_for_variables;
87use crate :: diagnostics:: utils:: {
98 build_field_mapping, is_doc_comment, report_error_if_not_applied_to_span, report_type_error,
109 should_generate_set_arg, type_is_bool, type_is_unit, type_matches_path, FieldInfo ,
1110 FieldInnerTy , FieldMap , HasFieldMap , SetOnce , SpannedOption , SubdiagnosticKind ,
1211} ;
1312use proc_macro2:: { Ident , Span , TokenStream , TokenTree } ;
14- use quote:: { format_ident, quote, quote_spanned, ToTokens } ;
13+ use quote:: { format_ident, quote, quote_spanned} ;
1514use std:: collections:: HashMap ;
1615use syn:: MetaList ;
1716use syn:: Token ;
@@ -66,9 +65,6 @@ pub(crate) struct DiagnosticDeriveVariantBuilder<'parent> {
6665
6766 /// Attributes on the variant.
6867 pub attrs : HashMap < String , LitStr > ,
69-
70- /// fields for bidnings in the variant.
71- pub fields : FieldMap ,
7268}
7369
7470impl < ' a > HasFieldMap for DiagnosticDeriveVariantBuilder < ' a > {
@@ -121,7 +117,6 @@ impl DiagnosticDeriveBuilder {
121117 code : None ,
122118 label : None ,
123119 attrs : HashMap :: new ( ) ,
124- fields : HashMap :: new ( ) ,
125120 } ;
126121 f ( builder, variant)
127122 } ) ;
@@ -140,9 +135,6 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
140135 pub fn preamble ( & mut self , variant : & VariantInfo < ' _ > ) -> TokenStream {
141136 let ast = variant. ast ( ) ;
142137 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- }
146138
147139 let preamble = attrs. iter ( ) . map ( |attr| {
148140 self . generate_structure_code_for_attr ( attr) . unwrap_or_else ( |v| v. to_compile_error ( ) )
@@ -193,7 +185,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
193185 SubdiagnosticKind :: MultipartSuggestion { .. } => unreachable ! ( ) ,
194186 } ) ;
195187
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 ( ) ) ) ) )
197189 }
198190
199191 /// Establishes state in the `DiagnosticDeriveBuilder` resulting from the struct
@@ -283,7 +275,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
283275 return Ok ( ( ) ) ;
284276 } ;
285277
286- if path. is_ident ( "text" ) || path . is_ident ( " label") {
278+ if path. is_ident ( "label" ) {
287279 let value = nested. parse :: < syn:: LitStr > ( ) ?;
288280 self . label . set_once ( value, path. span ( ) . unwrap ( ) ) ;
289281 } else if path. is_ident ( "code" ) {
@@ -314,15 +306,15 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
314306 return Ok ( tokens) ;
315307 }
316308
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 {
318310 // Some attributes aren't errors - like documentation comments - but also aren't
319311 // subdiagnostics.
320312 return Ok ( quote ! { } ) ;
321313 } ;
322314 let fn_ident = format_ident ! ( "{}" , subdiag) ;
323315 match subdiag {
324316 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 ) )
326318 }
327319 SubdiagnosticKind :: Label | SubdiagnosticKind :: Suggestion { .. } => {
328320 throw_invalid_attr ! ( attr, |diag| diag
@@ -349,16 +341,6 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
349341 }
350342 }
351343
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-
362344 fn generate_field_attrs_code ( & mut self , binding_info : & BindingInfo < ' _ > ) -> TokenStream {
363345 let field = binding_info. ast ( ) ;
364346 let field_binding = & binding_info. binding ;
@@ -474,7 +456,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
474456 _ => ( ) ,
475457 }
476458
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 {
478460 // Some attributes aren't errors - like documentation comments - but also aren't
479461 // subdiagnostics.
480462 return Ok ( quote ! { } ) ;
@@ -483,18 +465,18 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
483465 match subdiag {
484466 SubdiagnosticKind :: Label => {
485467 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 ) )
487469 }
488470 SubdiagnosticKind :: Note | SubdiagnosticKind :: Help | SubdiagnosticKind :: Warn => {
489471 let inner = info. ty . inner_type ( ) ;
490472 if type_matches_path ( inner, & [ "rustc_span" , "Span" ] )
491473 || type_matches_path ( inner, & [ "rustc_span" , "MultiSpan" ] )
492474 {
493- Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, text ) )
475+ Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, raw_label ) )
494476 } else if type_is_unit ( inner)
495477 || ( matches ! ( info. ty, FieldInnerTy :: Plain ( _) ) && type_is_bool ( inner) )
496478 {
497- Ok ( self . add_subdiagnostic ( & fn_ident, slug, text ) )
479+ Ok ( self . add_subdiagnostic ( & fn_ident, slug, raw_label ) )
498480 } else {
499481 report_type_error ( attr, "`Span`, `MultiSpan`, `bool` or `()`" ) ?
500482 }
@@ -525,10 +507,9 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
525507 . unwrap_or_else ( || quote ! { rustc_errors:: Applicability :: Unspecified } ) ;
526508 let style = suggestion_kind. to_suggestion_style ( ) ;
527509
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 {
530511 quote ! {
531- #text
512+ #raw_label
532513 }
533514 } else {
534515 quote ! {
@@ -558,24 +539,23 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
558539 field_binding : TokenStream ,
559540 kind : & Ident ,
560541 fluent_attr_identifier : Path ,
561- text : Option < String > ,
542+ raw_label : Option < String > ,
562543 ) -> TokenStream {
563544 let diag = & self . parent . diag ;
564545 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 {
567547 return quote ! {
568548 #diag. #fn_name(
569549 #field_binding,
570- #text
550+ #raw_label
571551 ) ;
572552 } ;
573553 }
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 ( ) ) {
575555 quote ! {
576556 #diag. #fn_name(
577557 #field_binding,
578- #text
558+ #raw_label
579559 ) ;
580560 }
581561 } else {
@@ -594,22 +574,17 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
594574 & self ,
595575 kind : & Ident ,
596576 fluent_attr_identifier : Path ,
597- text : Option < String > ,
577+ raw_label : Option < String > ,
598578 ) -> TokenStream {
599579 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 {
606581 return quote ! {
607- #diag. #kind( #text ) ;
582+ #diag. #kind( #raw_label ) ;
608583 } ;
609584 }
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 ( ) ) {
611586 quote ! {
612- #diag. #kind( #text ) ;
587+ #diag. #kind( #raw_label ) ;
613588 }
614589 } else {
615590 quote ! {
@@ -677,7 +652,6 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
677652
678653 fn get_attr ( & self , key : & str ) -> Option < TokenStream > {
679654 self . attrs . get ( key) . map ( |val| {
680- //let text = format_for_variables(&val.value(), &self.fields);
681655 let text = & val. value ( ) ;
682656 quote ! {
683657 #text
0 commit comments