@@ -67,6 +67,7 @@ impl<'a> Parser<'a> {
6767 token:: CommentKind :: Line => OuterAttributeType :: DocComment ,
6868 token:: CommentKind :: Block => OuterAttributeType :: DocBlockComment ,
6969 } ,
70+ true ,
7071 ) {
7172 err. note ( fluent:: parse_note) ;
7273 err. span_suggestion_verbose (
@@ -130,7 +131,11 @@ impl<'a> Parser<'a> {
130131
131132 // Emit error if inner attribute is encountered and forbidden.
132133 if style == ast:: AttrStyle :: Inner {
133- this. error_on_forbidden_inner_attr ( attr_sp, inner_parse_policy) ;
134+ this. error_on_forbidden_inner_attr (
135+ attr_sp,
136+ inner_parse_policy,
137+ item. is_valid_for_outer_style ( ) ,
138+ ) ;
134139 }
135140
136141 Ok ( attr:: mk_attr_from_item ( & self . psess . attr_id_generator , item, None , style, attr_sp) )
@@ -142,6 +147,7 @@ impl<'a> Parser<'a> {
142147 err : & mut Diag < ' _ > ,
143148 span : Span ,
144149 attr_type : OuterAttributeType ,
150+ suggest_to_outer : bool ,
145151 ) -> Option < Span > {
146152 let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
147153 let lo = span. lo ( )
@@ -176,16 +182,18 @@ impl<'a> Parser<'a> {
176182 // FIXME(#100717)
177183 err. arg ( "item" , item. kind . descr ( ) ) ;
178184 err. span_label ( item. span , fluent:: parse_label_does_not_annotate_this) ;
179- err. span_suggestion_verbose (
180- replacement_span,
181- fluent:: parse_sugg_change_inner_to_outer,
182- match attr_type {
183- OuterAttributeType :: Attribute => "" ,
184- OuterAttributeType :: DocBlockComment => "*" ,
185- OuterAttributeType :: DocComment => "/" ,
186- } ,
187- rustc_errors:: Applicability :: MachineApplicable ,
188- ) ;
185+ if suggest_to_outer {
186+ err. span_suggestion_verbose (
187+ replacement_span,
188+ fluent:: parse_sugg_change_inner_to_outer,
189+ match attr_type {
190+ OuterAttributeType :: Attribute => "" ,
191+ OuterAttributeType :: DocBlockComment => "*" ,
192+ OuterAttributeType :: DocComment => "/" ,
193+ } ,
194+ rustc_errors:: Applicability :: MachineApplicable ,
195+ ) ;
196+ }
189197 return None ;
190198 }
191199 Err ( item_err) => {
@@ -196,7 +204,12 @@ impl<'a> Parser<'a> {
196204 Some ( replacement_span)
197205 }
198206
199- pub ( super ) fn error_on_forbidden_inner_attr ( & self , attr_sp : Span , policy : InnerAttrPolicy ) {
207+ pub ( super ) fn error_on_forbidden_inner_attr (
208+ & self ,
209+ attr_sp : Span ,
210+ policy : InnerAttrPolicy ,
211+ suggest_to_outer : bool ,
212+ ) {
200213 if let InnerAttrPolicy :: Forbidden ( reason) = policy {
201214 let mut diag = match reason. as_ref ( ) . copied ( ) {
202215 Some ( InnerAttrForbiddenReason :: AfterOuterDocComment { prev_doc_comment_span } ) => {
@@ -230,6 +243,7 @@ impl<'a> Parser<'a> {
230243 & mut diag,
231244 attr_sp,
232245 OuterAttributeType :: Attribute ,
246+ suggest_to_outer,
233247 )
234248 . is_some ( )
235249 {
0 commit comments