@@ -15,6 +15,8 @@ use std::str::FromStr;
1515use syn:: { spanned:: Spanned , Attribute , Meta , MetaList , MetaNameValue , NestedMeta , Path } ;
1616use synstructure:: { BindingInfo , Structure , VariantInfo } ;
1717
18+ use super :: utils:: SpannedOption ;
19+
1820/// Which kind of suggestion is being created?
1921#[ derive( Clone , Copy ) ]
2022enum SubdiagnosticSuggestionKind {
@@ -195,10 +197,10 @@ struct SubdiagnosticDeriveBuilder<'a> {
195197 fields : HashMap < String , TokenStream > ,
196198
197199 /// Identifier for the binding to the `#[primary_span]` field.
198- span_field : Option < ( proc_macro2:: Ident , proc_macro :: Span ) > ,
200+ span_field : SpannedOption < proc_macro2:: Ident > ,
199201 /// If a suggestion, the identifier for the binding to the `#[applicability]` field or a
200202 /// `rustc_errors::Applicability::*` variant directly.
201- applicability : Option < ( TokenStream , proc_macro :: Span ) > ,
203+ applicability : SpannedOption < TokenStream > ,
202204
203205 /// Set to true when a `#[suggestion_part]` field is encountered, used to generate an error
204206 /// during finalization if still `false`.
@@ -283,7 +285,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
283285 if let Some ( nested_attr) = nested_iter. next ( ) {
284286 match nested_attr {
285287 NestedMeta :: Meta ( Meta :: Path ( path) ) => {
286- slug. set_once ( ( path. clone ( ) , span) ) ;
288+ slug. set_once ( path. clone ( ) , span) ;
287289 }
288290 NestedMeta :: Meta ( meta @ Meta :: NameValue ( _) )
289291 if matches ! (
@@ -326,7 +328,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
326328 "code" => {
327329 if matches ! ( kind, SubdiagnosticKind :: Suggestion { .. } ) {
328330 let formatted_str = self . build_format ( & value. value ( ) , value. span ( ) ) ;
329- code. set_once ( ( formatted_str, span) ) ;
331+ code. set_once ( formatted_str, span) ;
330332 } else {
331333 span_err (
332334 span,
@@ -349,7 +351,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
349351 span_err ( span, "invalid applicability" ) . emit ( ) ;
350352 Applicability :: Unspecified
351353 } ) ;
352- self . applicability . set_once ( ( quote ! { #value } , span) ) ;
354+ self . applicability . set_once ( quote ! { #value } , span) ;
353355 } else {
354356 span_err (
355357 span,
@@ -485,7 +487,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
485487 report_error_if_not_applied_to_span ( attr, & info) ?;
486488
487489 let binding = info. binding . binding . clone ( ) ;
488- self . span_field . set_once ( ( binding, span) ) ;
490+ self . span_field . set_once ( binding, span) ;
489491
490492 Ok ( quote ! { } )
491493 }
@@ -509,7 +511,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
509511 report_error_if_not_applied_to_applicability ( attr, & info) ?;
510512
511513 let binding = info. binding . binding . clone ( ) ;
512- self . applicability . set_once ( ( quote ! { #binding } , span) ) ;
514+ self . applicability . set_once ( quote ! { #binding } , span) ;
513515 } else {
514516 span_err ( span, "`#[applicability]` is only valid on suggestions" ) . emit ( ) ;
515517 }
@@ -577,7 +579,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
577579 match nested_name {
578580 "code" => {
579581 let formatted_str = self . build_format ( & value. value ( ) , value. span ( ) ) ;
580- code. set_once ( ( formatted_str, span) ) ;
582+ code. set_once ( formatted_str, span) ;
581583 }
582584 _ => throw_invalid_nested_attr ! ( attr, & nested_attr, |diag| {
583585 diag. help( "`code` is the only valid nested attribute" )
@@ -635,11 +637,12 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
635637 . map ( |binding| self . generate_field_attr_code ( binding, kind_stats) )
636638 . collect ( ) ;
637639
638- let span_field = self . span_field . as_ref ( ) . map ( |( span, _) | span) ;
639- let applicability = self . applicability . take ( ) . map_or_else (
640- || quote ! { rustc_errors:: Applicability :: Unspecified } ,
641- |( applicability, _) | applicability,
642- ) ;
640+ let span_field = self . span_field . value_ref ( ) ;
641+ let applicability = self
642+ . applicability
643+ . take ( )
644+ . value ( )
645+ . unwrap_or_else ( || quote ! { rustc_errors:: Applicability :: Unspecified } ) ;
643646
644647 let diag = & self . diag ;
645648 let mut calls = TokenStream :: new ( ) ;
0 commit comments