@@ -132,28 +132,45 @@ pub struct AttributeTemplate {
132132 pub docs : Option < & ' static str > ,
133133}
134134
135+ pub enum AttrSuggestionStyle {
136+ /// The suggestion is styled for a normal attribute.
137+ /// The `AttrStyle` determines whether this is an inner or outer attribute.
138+ Attribute ( AttrStyle ) ,
139+ /// The suggestion is styled for an attribute embedded into another attribute.
140+ /// For example, attributes inside `#[cfg_attr(true, attr(...)]`.
141+ EmbeddedAttribute ,
142+ /// The suggestion is styled for macros that are parsed with attribute parsers.
143+ /// For example, the `cfg!(predicate)` macro.
144+ Macro ,
145+ }
146+
135147impl AttributeTemplate {
136148 pub fn suggestions (
137149 & self ,
138- style : Option < AttrStyle > ,
150+ style : AttrSuggestionStyle ,
139151 name : impl std:: fmt:: Display ,
140152 ) -> Vec < String > {
141- let mut suggestions = vec ! [ ] ;
142- let ( start , end ) = match style {
143- Some ( AttrStyle :: Outer ) => ( "#[ " , "]" ) ,
144- Some ( AttrStyle :: Inner ) => ( "#![ " , "] " ) ,
145- None => ( "" , "" ) ,
153+ let ( start , macro_call , end ) = match style {
154+ AttrSuggestionStyle :: Attribute ( AttrStyle :: Outer ) => ( "#[" , "" , "]" ) ,
155+ AttrSuggestionStyle :: Attribute ( AttrStyle :: Inner ) => ( "#![" , " ", "]" ) ,
156+ AttrSuggestionStyle :: Macro => ( "" , "! ", "" ) ,
157+ AttrSuggestionStyle :: EmbeddedAttribute => ( "" , "" , "" ) ,
146158 } ;
159+
160+ let mut suggestions = vec ! [ ] ;
161+
147162 if self . word {
163+ debug_assert ! ( macro_call. is_empty( ) , "Macro suggestions use list style" ) ;
148164 suggestions. push ( format ! ( "{start}{name}{end}" ) ) ;
149165 }
150166 if let Some ( descr) = self . list {
151167 for descr in descr {
152- suggestions. push ( format ! ( "{start}{name}({descr}){end}" ) ) ;
168+ suggestions. push ( format ! ( "{start}{name}{macro_call} ({descr}){end}" ) ) ;
153169 }
154170 }
155171 suggestions. extend ( self . one_of . iter ( ) . map ( |& word| format ! ( "{start}{name}({word}){end}" ) ) ) ;
156172 if let Some ( descr) = self . name_value_str {
173+ debug_assert ! ( macro_call. is_empty( ) , "Macro suggestions use list style" ) ;
157174 for descr in descr {
158175 suggestions. push ( format ! ( "{start}{name} = \" {descr}\" {end}" ) ) ;
159176 }
0 commit comments