@@ -12,7 +12,7 @@ use syn::{spanned::Spanned, Attribute, Field, Meta, Type, TypeTuple};
1212use syn:: { MetaList , MetaNameValue , NestedMeta , Path } ;
1313use synstructure:: { BindingInfo , VariantInfo } ;
1414
15- use super :: error:: invalid_nested_attr;
15+ use super :: error:: { invalid_attr , invalid_nested_attr} ;
1616
1717thread_local ! {
1818 pub static CODE_IDENT_COUNT : RefCell <u32 > = RefCell :: new( 0 ) ;
@@ -496,6 +496,18 @@ impl FromStr for SuggestionKind {
496496 }
497497}
498498
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+
499511impl SuggestionKind {
500512 pub fn to_suggestion_style ( & self ) -> TokenStream {
501513 match self {
@@ -577,21 +589,24 @@ impl SubdiagnosticKind {
577589
578590 let meta = attr. parse_meta ( ) ?;
579591
580- let mut opt_suggestion_kind = None ;
581592 let mut kind = match name {
582593 "label" => SubdiagnosticKind :: Label ,
583594 "note" => SubdiagnosticKind :: Note ,
584595 "help" => SubdiagnosticKind :: Help ,
585596 "warning" => SubdiagnosticKind :: Warn ,
586597 _ => {
587- // FIXME(#100717): remove #[ suggestion_{short,verbose,hidden}] attributes, use
588- // #[suggestion(style = "...")] instead
598+ // Recover old `#[(multipart_) suggestion_*]` syntaxes
599+ // FIXME(#100717): remove
589600 if let Some ( suggestion_kind) =
590601 name. strip_prefix ( "suggestion" ) . and_then ( SuggestionKind :: from_suffix)
591602 {
592603 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 ( ) ;
595610 }
596611
597612 SubdiagnosticKind :: Suggestion {
@@ -604,8 +619,12 @@ impl SubdiagnosticKind {
604619 name. strip_prefix ( "multipart_suggestion" ) . and_then ( SuggestionKind :: from_suffix)
605620 {
606621 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 ( ) ;
609628 }
610629
611630 SubdiagnosticKind :: MultipartSuggestion {
@@ -649,6 +668,7 @@ impl SubdiagnosticKind {
649668 } ;
650669
651670 let mut code = None ;
671+ let mut suggestion_kind = None ;
652672
653673 let mut nested_iter = nested. into_iter ( ) . peekable ( ) ;
654674
@@ -727,7 +747,7 @@ impl SubdiagnosticKind {
727747 SuggestionKind :: Normal
728748 } ) ;
729749
730- opt_suggestion_kind . set_once ( value, span) ;
750+ suggestion_kind . set_once ( value, span) ;
731751 }
732752
733753 // Invalid nested attribute
@@ -753,11 +773,11 @@ impl SubdiagnosticKind {
753773 SubdiagnosticKind :: Suggestion {
754774 ref code_field,
755775 ref mut code_init,
756- ref mut suggestion_kind ,
776+ suggestion_kind : ref mut kind_field ,
757777 ..
758778 } => {
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;
761781 }
762782
763783 * code_init = if let Some ( init) = code. value ( ) {
@@ -767,9 +787,11 @@ impl SubdiagnosticKind {
767787 quote ! { let #code_field = std:: iter:: empty( ) ; }
768788 } ;
769789 }
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;
773795 }
774796 }
775797 SubdiagnosticKind :: Label
0 commit comments