@@ -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 ;
@@ -56,9 +55,6 @@ pub(crate) struct DiagnosticDeriveVariantBuilder {
5655
5756 /// Attributes on the variant.
5857 pub attrs : HashMap < String , LitStr > ,
59-
60- /// fields for bidnings in the variant.
61- pub fields : FieldMap ,
6258}
6359
6460impl HasFieldMap for DiagnosticDeriveVariantBuilder {
@@ -111,7 +107,6 @@ impl DiagnosticDeriveKind {
111107 code : None ,
112108 label : None ,
113109 attrs : HashMap :: new ( ) ,
114- fields : HashMap :: new ( ) ,
115110 } ;
116111 f ( builder, variant)
117112 } ) ;
@@ -130,9 +125,6 @@ impl DiagnosticDeriveVariantBuilder {
130125 pub ( crate ) fn preamble ( & mut self , variant : & VariantInfo < ' _ > ) -> TokenStream {
131126 let ast = variant. ast ( ) ;
132127 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- }
136128
137129 let preamble = attrs. iter ( ) . map ( |attr| {
138130 self . generate_structure_code_for_attr ( attr) . unwrap_or_else ( |v| v. to_compile_error ( ) )
@@ -183,7 +175,7 @@ impl DiagnosticDeriveVariantBuilder {
183175 SubdiagnosticKind :: MultipartSuggestion { .. } => unreachable ! ( ) ,
184176 } ) ;
185177
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 ( ) ) ) ) )
187179 }
188180
189181 /// Establishes state in the `DiagnosticDeriveBuilder` resulting from the struct
@@ -271,7 +263,7 @@ impl DiagnosticDeriveVariantBuilder {
271263 return Ok ( ( ) ) ;
272264 } ;
273265
274- if path. is_ident ( "text" ) || path . is_ident ( " label") {
266+ if path. is_ident ( "label" ) {
275267 let value = nested. parse :: < syn:: LitStr > ( ) ?;
276268 self . label . set_once ( value, path. span ( ) . unwrap ( ) ) ;
277269 } else if path. is_ident ( "code" ) {
@@ -302,15 +294,15 @@ impl DiagnosticDeriveVariantBuilder {
302294 return Ok ( tokens) ;
303295 }
304296
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 {
306298 // Some attributes aren't errors - like documentation comments - but also aren't
307299 // subdiagnostics.
308300 return Ok ( quote ! { } ) ;
309301 } ;
310302 let fn_ident = format_ident ! ( "{}" , subdiag) ;
311303 match subdiag {
312304 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 ) )
314306 }
315307 SubdiagnosticKind :: Label | SubdiagnosticKind :: Suggestion { .. } => {
316308 throw_invalid_attr ! ( attr, |diag| diag
@@ -335,16 +327,6 @@ impl DiagnosticDeriveVariantBuilder {
335327 }
336328 }
337329
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-
348330 fn generate_field_attrs_code ( & mut self , binding_info : & BindingInfo < ' _ > ) -> TokenStream {
349331 let field = binding_info. ast ( ) ;
350332 let field_binding = & binding_info. binding ;
@@ -458,7 +440,7 @@ impl DiagnosticDeriveVariantBuilder {
458440 _ => ( ) ,
459441 }
460442
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 {
462444 // Some attributes aren't errors - like documentation comments - but also aren't
463445 // subdiagnostics.
464446 return Ok ( quote ! { } ) ;
@@ -467,18 +449,18 @@ impl DiagnosticDeriveVariantBuilder {
467449 match subdiag {
468450 SubdiagnosticKind :: Label => {
469451 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 ) )
471453 }
472454 SubdiagnosticKind :: Note | SubdiagnosticKind :: Help | SubdiagnosticKind :: Warn => {
473455 let inner = info. ty . inner_type ( ) ;
474456 if type_matches_path ( inner, & [ "rustc_span" , "Span" ] )
475457 || type_matches_path ( inner, & [ "rustc_span" , "MultiSpan" ] )
476458 {
477- Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, text ) )
459+ Ok ( self . add_spanned_subdiagnostic ( binding, & fn_ident, slug, raw_label ) )
478460 } else if type_is_unit ( inner)
479461 || ( matches ! ( info. ty, FieldInnerTy :: Plain ( _) ) && type_is_bool ( inner) )
480462 {
481- Ok ( self . add_subdiagnostic ( & fn_ident, slug, text ) )
463+ Ok ( self . add_subdiagnostic ( & fn_ident, slug, raw_label ) )
482464 } else {
483465 report_type_error ( attr, "`Span`, `MultiSpan`, `bool` or `()`" ) ?
484466 }
@@ -509,10 +491,9 @@ impl DiagnosticDeriveVariantBuilder {
509491 . unwrap_or_else ( || quote ! { rustc_errors:: Applicability :: Unspecified } ) ;
510492 let style = suggestion_kind. to_suggestion_style ( ) ;
511493
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 {
514495 quote ! {
515- #text
496+ #raw_label
516497 }
517498 } else {
518499 quote ! {
@@ -542,23 +523,22 @@ impl DiagnosticDeriveVariantBuilder {
542523 field_binding : TokenStream ,
543524 kind : & Ident ,
544525 fluent_attr_identifier : Path ,
545- text : Option < String > ,
526+ raw_label : Option < String > ,
546527 ) -> TokenStream {
547528 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 {
550530 return quote ! {
551531 #diag. #fn_name(
552532 #field_binding,
553- #text
533+ #raw_label
554534 ) ;
555535 } ;
556536 }
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 ( ) ) {
558538 quote ! {
559539 #diag. #fn_name(
560540 #field_binding,
561- #text
541+ #raw_label
562542 ) ;
563543 }
564544 } else {
@@ -577,22 +557,17 @@ impl DiagnosticDeriveVariantBuilder {
577557 & self ,
578558 kind : & Ident ,
579559 fluent_attr_identifier : Path ,
580- text : Option < String > ,
560+ raw_label : Option < String > ,
581561 ) -> TokenStream {
582562 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 {
589564 return quote ! {
590- #diag. #kind( #text ) ;
565+ #diag. #kind( #raw_label ) ;
591566 } ;
592567 }
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 ( ) ) {
594569 quote ! {
595- #diag. #kind( #text ) ;
570+ #diag. #kind( #raw_label ) ;
596571 }
597572 } else {
598573 quote ! {
@@ -660,7 +635,6 @@ impl DiagnosticDeriveVariantBuilder {
660635
661636 fn get_attr ( & self , key : & str ) -> Option < TokenStream > {
662637 self . attrs . get ( key) . map ( |val| {
663- //let text = format_for_variables(&val.value(), &self.fields);
664638 let text = & val. value ( ) ;
665639 quote ! {
666640 #text
0 commit comments