@@ -76,6 +76,7 @@ impl<'a> Parser<'a> {
7676 token:: CommentKind :: Line => OuterAttributeType :: DocComment ,
7777 token:: CommentKind :: Block => OuterAttributeType :: DocBlockComment ,
7878 } ,
79+ true ,
7980 ) {
8081 err. note ( fluent:: parse_note) ;
8182 err. span_suggestion_verbose (
@@ -139,7 +140,11 @@ impl<'a> Parser<'a> {
139140
140141 // Emit error if inner attribute is encountered and forbidden.
141142 if style == ast:: AttrStyle :: Inner {
142- this. error_on_forbidden_inner_attr ( attr_sp, inner_parse_policy) ;
143+ this. error_on_forbidden_inner_attr (
144+ attr_sp,
145+ inner_parse_policy,
146+ item. is_valid_for_outer_style ( ) ,
147+ ) ;
143148 }
144149
145150 Ok ( attr:: mk_attr_from_item ( & self . psess . attr_id_generator , item, None , style, attr_sp) )
@@ -151,6 +156,7 @@ impl<'a> Parser<'a> {
151156 err : & mut Diag < ' _ > ,
152157 span : Span ,
153158 attr_type : OuterAttributeType ,
159+ suggest_to_outer : bool ,
154160 ) -> Option < Span > {
155161 let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
156162 let lo = span. lo ( )
@@ -185,16 +191,18 @@ impl<'a> Parser<'a> {
185191 // FIXME(#100717)
186192 err. arg ( "item" , item. kind . descr ( ) ) ;
187193 err. span_label ( item. span , fluent:: parse_label_does_not_annotate_this) ;
188- err. span_suggestion_verbose (
189- replacement_span,
190- fluent:: parse_sugg_change_inner_to_outer,
191- match attr_type {
192- OuterAttributeType :: Attribute => "" ,
193- OuterAttributeType :: DocBlockComment => "*" ,
194- OuterAttributeType :: DocComment => "/" ,
195- } ,
196- rustc_errors:: Applicability :: MachineApplicable ,
197- ) ;
194+ if suggest_to_outer {
195+ err. span_suggestion_verbose (
196+ replacement_span,
197+ fluent:: parse_sugg_change_inner_to_outer,
198+ match attr_type {
199+ OuterAttributeType :: Attribute => "" ,
200+ OuterAttributeType :: DocBlockComment => "*" ,
201+ OuterAttributeType :: DocComment => "/" ,
202+ } ,
203+ rustc_errors:: Applicability :: MachineApplicable ,
204+ ) ;
205+ }
198206 return None ;
199207 }
200208 Err ( item_err) => {
@@ -205,7 +213,12 @@ impl<'a> Parser<'a> {
205213 Some ( replacement_span)
206214 }
207215
208- pub ( super ) fn error_on_forbidden_inner_attr ( & self , attr_sp : Span , policy : InnerAttrPolicy ) {
216+ pub ( super ) fn error_on_forbidden_inner_attr (
217+ & self ,
218+ attr_sp : Span ,
219+ policy : InnerAttrPolicy ,
220+ suggest_to_outer : bool ,
221+ ) {
209222 if let InnerAttrPolicy :: Forbidden ( reason) = policy {
210223 let mut diag = match reason. as_ref ( ) . copied ( ) {
211224 Some ( InnerAttrForbiddenReason :: AfterOuterDocComment { prev_doc_comment_span } ) => {
@@ -239,6 +252,7 @@ impl<'a> Parser<'a> {
239252 & mut diag,
240253 attr_sp,
241254 OuterAttributeType :: Attribute ,
255+ suggest_to_outer,
242256 )
243257 . is_some ( )
244258 {
0 commit comments