@@ -12,7 +12,7 @@ use syn::{spanned::Spanned, Attribute, Field, Meta, Type, TypeTuple};
12
12
use syn:: { MetaList , MetaNameValue , NestedMeta , Path } ;
13
13
use synstructure:: { BindingInfo , VariantInfo } ;
14
14
15
- use super :: error:: invalid_nested_attr;
15
+ use super :: error:: { invalid_attr , invalid_nested_attr} ;
16
16
17
17
thread_local ! {
18
18
pub static CODE_IDENT_COUNT : RefCell <u32 > = RefCell :: new( 0 ) ;
@@ -496,6 +496,18 @@ impl FromStr for SuggestionKind {
496
496
}
497
497
}
498
498
499
+ impl fmt:: Display for SuggestionKind {
500
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
501
+ match self {
502
+ SuggestionKind :: Normal => write ! ( f, "normal" ) ,
503
+ SuggestionKind :: Short => write ! ( f, "short" ) ,
504
+ SuggestionKind :: Hidden => write ! ( f, "hidden" ) ,
505
+ SuggestionKind :: Verbose => write ! ( f, "verbose" ) ,
506
+ SuggestionKind :: ToolOnly => write ! ( f, "tool-only" ) ,
507
+ }
508
+ }
509
+ }
510
+
499
511
impl SuggestionKind {
500
512
pub fn to_suggestion_style ( & self ) -> TokenStream {
501
513
match self {
@@ -577,21 +589,24 @@ impl SubdiagnosticKind {
577
589
578
590
let meta = attr. parse_meta ( ) ?;
579
591
580
- let mut opt_suggestion_kind = None ;
581
592
let mut kind = match name {
582
593
"label" => SubdiagnosticKind :: Label ,
583
594
"note" => SubdiagnosticKind :: Note ,
584
595
"help" => SubdiagnosticKind :: Help ,
585
596
"warning" => SubdiagnosticKind :: Warn ,
586
597
_ => {
587
- // FIXME(#100717): remove #[ suggestion_{short,verbose,hidden}] attributes, use
588
- // #[suggestion(style = "...")] instead
598
+ // Recover old `#[(multipart_) suggestion_*]` syntaxes
599
+ // FIXME(#100717): remove
589
600
if let Some ( suggestion_kind) =
590
601
name. strip_prefix ( "suggestion" ) . and_then ( SuggestionKind :: from_suffix)
591
602
{
592
603
if suggestion_kind != SuggestionKind :: Normal {
593
- // Plain `#[suggestion]` can have a `style = "..."` attribute later, so don't set it here
594
- opt_suggestion_kind. set_once ( suggestion_kind, attr. path . span ( ) . unwrap ( ) ) ;
604
+ invalid_attr ( attr, & meta)
605
+ . help ( format ! (
606
+ r#"Use `#[suggestion(..., style = "{}")]` instead"# ,
607
+ suggestion_kind
608
+ ) )
609
+ . emit ( ) ;
595
610
}
596
611
597
612
SubdiagnosticKind :: Suggestion {
@@ -604,8 +619,12 @@ impl SubdiagnosticKind {
604
619
name. strip_prefix ( "multipart_suggestion" ) . and_then ( SuggestionKind :: from_suffix)
605
620
{
606
621
if suggestion_kind != SuggestionKind :: Normal {
607
- // Plain `#[multipart_suggestion]` can have a `style = "..."` attribute later, so don't set it here
608
- opt_suggestion_kind. set_once ( suggestion_kind, attr. path . span ( ) . unwrap ( ) ) ;
622
+ invalid_attr ( attr, & meta)
623
+ . help ( format ! (
624
+ r#"Use `#[multipart_suggestion(..., style = "{}")]` instead"# ,
625
+ suggestion_kind
626
+ ) )
627
+ . emit ( ) ;
609
628
}
610
629
611
630
SubdiagnosticKind :: MultipartSuggestion {
@@ -649,6 +668,7 @@ impl SubdiagnosticKind {
649
668
} ;
650
669
651
670
let mut code = None ;
671
+ let mut suggestion_kind = None ;
652
672
653
673
let mut nested_iter = nested. into_iter ( ) . peekable ( ) ;
654
674
@@ -727,7 +747,7 @@ impl SubdiagnosticKind {
727
747
SuggestionKind :: Normal
728
748
} ) ;
729
749
730
- opt_suggestion_kind . set_once ( value, span) ;
750
+ suggestion_kind . set_once ( value, span) ;
731
751
}
732
752
733
753
// Invalid nested attribute
@@ -753,11 +773,11 @@ impl SubdiagnosticKind {
753
773
SubdiagnosticKind :: Suggestion {
754
774
ref code_field,
755
775
ref mut code_init,
756
- ref mut suggestion_kind ,
776
+ suggestion_kind : ref mut kind_field ,
757
777
..
758
778
} => {
759
- if let Some ( kind) = opt_suggestion_kind . value ( ) {
760
- * suggestion_kind = kind;
779
+ if let Some ( kind) = suggestion_kind . value ( ) {
780
+ * kind_field = kind;
761
781
}
762
782
763
783
* code_init = if let Some ( init) = code. value ( ) {
@@ -767,9 +787,11 @@ impl SubdiagnosticKind {
767
787
quote ! { let #code_field = std:: iter:: empty( ) ; }
768
788
} ;
769
789
}
770
- SubdiagnosticKind :: MultipartSuggestion { ref mut suggestion_kind, .. } => {
771
- if let Some ( kind) = opt_suggestion_kind. value ( ) {
772
- * suggestion_kind = kind;
790
+ SubdiagnosticKind :: MultipartSuggestion {
791
+ suggestion_kind : ref mut kind_field, ..
792
+ } => {
793
+ if let Some ( kind) = suggestion_kind. value ( ) {
794
+ * kind_field = kind;
773
795
}
774
796
}
775
797
SubdiagnosticKind :: Label
0 commit comments