33use std:: sync:: LazyLock ;
44
55use AttributeGate :: * ;
6+ use rustc_ast:: ast:: Safety ;
67use rustc_data_structures:: fx:: FxHashMap ;
78use rustc_hir:: AttrStyle ;
89use rustc_span:: { Symbol , sym} ;
@@ -118,7 +119,7 @@ impl AttributeTemplate {
118119 pub fn suggestions (
119120 & self ,
120121 style : AttrSuggestionStyle ,
121- wrap_with_unsafe : bool ,
122+ safety : Safety ,
122123 name : impl std:: fmt:: Display ,
123124 ) -> Vec < String > {
124125 let ( start, macro_call, end) = match style {
@@ -130,29 +131,32 @@ impl AttributeTemplate {
130131
131132 let mut suggestions = vec ! [ ] ;
132133
133- let ( maybe_unsafe_start, maybe_unsafe_end) =
134- if wrap_with_unsafe { ( "unsafe(" , ")" ) } else { ( "" , "" ) } ;
134+ let ( safety_start, safety_end) = match safety {
135+ Safety :: Unsafe ( _) => ( "unsafe(" , ")" ) ,
136+ _ => ( "" , "" ) ,
137+ } ;
135138
136139 if self . word {
137140 debug_assert ! ( macro_call. is_empty( ) , "Macro suggestions use list style" ) ;
138- suggestions. push ( format ! ( "{start}{maybe_unsafe_start }{name}{maybe_unsafe_end }{end}" ) ) ;
141+ suggestions. push ( format ! ( "{start}{safety_start }{name}{safety_end }{end}" ) ) ;
139142 }
140143 if let Some ( descr) = self . list {
141144 for descr in descr {
142145 suggestions. push ( format ! (
143- "{start}{maybe_unsafe_start }{name}{macro_call}({descr}){maybe_unsafe_end }{end}"
146+ "{start}{safety_start }{name}{macro_call}({descr}){safety_end }{end}"
144147 ) ) ;
145148 }
146149 }
147- suggestions. extend ( self . one_of . iter ( ) . map ( |& word| {
148- format ! ( "{start}{maybe_unsafe_start}{name}({word}){maybe_unsafe_end}{end}" )
149- } ) ) ;
150+ suggestions. extend (
151+ self . one_of
152+ . iter ( )
153+ . map ( |& word| format ! ( "{start}{safety_start}{name}({word}){safety_end}{end}" ) ) ,
154+ ) ;
150155 if let Some ( descr) = self . name_value_str {
151156 debug_assert ! ( macro_call. is_empty( ) , "Macro suggestions use list style" ) ;
152157 for descr in descr {
153- suggestions. push ( format ! (
154- "{start}{maybe_unsafe_start}{name} = \" {descr}\" {maybe_unsafe_end}{end}"
155- ) ) ;
158+ suggestions
159+ . push ( format ! ( "{start}{safety_start}{name} = \" {descr}\" {safety_end}{end}" ) ) ;
156160 }
157161 }
158162 suggestions. sort ( ) ;
0 commit comments