@@ -15,6 +15,8 @@ use std::str::FromStr;
15
15
use syn:: { spanned:: Spanned , Attribute , Meta , MetaList , MetaNameValue , NestedMeta , Path } ;
16
16
use synstructure:: { BindingInfo , Structure , VariantInfo } ;
17
17
18
+ use super :: utils:: SpannedOption ;
19
+
18
20
/// Which kind of suggestion is being created?
19
21
#[ derive( Clone , Copy ) ]
20
22
enum SubdiagnosticSuggestionKind {
@@ -195,10 +197,10 @@ struct SubdiagnosticDeriveBuilder<'a> {
195
197
fields : HashMap < String , TokenStream > ,
196
198
197
199
/// 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 > ,
199
201
/// If a suggestion, the identifier for the binding to the `#[applicability]` field or a
200
202
/// `rustc_errors::Applicability::*` variant directly.
201
- applicability : Option < ( TokenStream , proc_macro :: Span ) > ,
203
+ applicability : SpannedOption < TokenStream > ,
202
204
203
205
/// Set to true when a `#[suggestion_part]` field is encountered, used to generate an error
204
206
/// during finalization if still `false`.
@@ -283,7 +285,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
283
285
if let Some ( nested_attr) = nested_iter. next ( ) {
284
286
match nested_attr {
285
287
NestedMeta :: Meta ( Meta :: Path ( path) ) => {
286
- slug. set_once ( ( path. clone ( ) , span) ) ;
288
+ slug. set_once ( path. clone ( ) , span) ;
287
289
}
288
290
NestedMeta :: Meta ( meta @ Meta :: NameValue ( _) )
289
291
if matches ! (
@@ -326,7 +328,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
326
328
"code" => {
327
329
if matches ! ( kind, SubdiagnosticKind :: Suggestion { .. } ) {
328
330
let formatted_str = self . build_format ( & value. value ( ) , value. span ( ) ) ;
329
- code. set_once ( ( formatted_str, span) ) ;
331
+ code. set_once ( formatted_str, span) ;
330
332
} else {
331
333
span_err (
332
334
span,
@@ -349,7 +351,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
349
351
span_err ( span, "invalid applicability" ) . emit ( ) ;
350
352
Applicability :: Unspecified
351
353
} ) ;
352
- self . applicability . set_once ( ( quote ! { #value } , span) ) ;
354
+ self . applicability . set_once ( quote ! { #value } , span) ;
353
355
} else {
354
356
span_err (
355
357
span,
@@ -485,7 +487,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
485
487
report_error_if_not_applied_to_span ( attr, & info) ?;
486
488
487
489
let binding = info. binding . binding . clone ( ) ;
488
- self . span_field . set_once ( ( binding, span) ) ;
490
+ self . span_field . set_once ( binding, span) ;
489
491
490
492
Ok ( quote ! { } )
491
493
}
@@ -509,7 +511,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
509
511
report_error_if_not_applied_to_applicability ( attr, & info) ?;
510
512
511
513
let binding = info. binding . binding . clone ( ) ;
512
- self . applicability . set_once ( ( quote ! { #binding } , span) ) ;
514
+ self . applicability . set_once ( quote ! { #binding } , span) ;
513
515
} else {
514
516
span_err ( span, "`#[applicability]` is only valid on suggestions" ) . emit ( ) ;
515
517
}
@@ -577,7 +579,7 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
577
579
match nested_name {
578
580
"code" => {
579
581
let formatted_str = self . build_format ( & value. value ( ) , value. span ( ) ) ;
580
- code. set_once ( ( formatted_str, span) ) ;
582
+ code. set_once ( formatted_str, span) ;
581
583
}
582
584
_ => throw_invalid_nested_attr ! ( attr, & nested_attr, |diag| {
583
585
diag. help( "`code` is the only valid nested attribute" )
@@ -635,11 +637,12 @@ impl<'a> SubdiagnosticDeriveBuilder<'a> {
635
637
. map ( |binding| self . generate_field_attr_code ( binding, kind_stats) )
636
638
. collect ( ) ;
637
639
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 } ) ;
643
646
644
647
let diag = & self . diag ;
645
648
let mut calls = TokenStream :: new ( ) ;
0 commit comments