@@ -25,6 +25,7 @@ pub enum InnerAttrForbiddenReason {
2525 AfterOuterAttribute { prev_outer_attr_sp : Span } ,
2626}
2727
28+ #[ derive( PartialEq ) ]
2829enum OuterAttributeType {
2930 DocComment ,
3031 DocBlockComment ,
@@ -67,6 +68,7 @@ impl<'a> Parser<'a> {
6768 token:: CommentKind :: Line => OuterAttributeType :: DocComment ,
6869 token:: CommentKind :: Block => OuterAttributeType :: DocBlockComment ,
6970 } ,
71+ true ,
7072 ) {
7173 err. note ( fluent:: parse_note) ;
7274 err. span_suggestion_verbose (
@@ -130,7 +132,11 @@ impl<'a> Parser<'a> {
130132
131133 // Emit error if inner attribute is encountered and forbidden.
132134 if style == ast:: AttrStyle :: Inner {
133- this. error_on_forbidden_inner_attr ( attr_sp, inner_parse_policy) ;
135+ this. error_on_forbidden_inner_attr (
136+ attr_sp,
137+ inner_parse_policy,
138+ item. is_valid_for_inner_outer_sytle ( ) ,
139+ ) ;
134140 }
135141
136142 Ok ( attr:: mk_attr_from_item ( & self . psess . attr_id_generator , item, None , style, attr_sp) )
@@ -142,6 +148,7 @@ impl<'a> Parser<'a> {
142148 err : & mut Diag < ' _ > ,
143149 span : Span ,
144150 attr_type : OuterAttributeType ,
151+ suggest_to_outer : bool ,
145152 ) -> Option < Span > {
146153 let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
147154 let lo = span. lo ( )
@@ -176,16 +183,18 @@ impl<'a> Parser<'a> {
176183 // FIXME(#100717)
177184 err. arg ( "item" , item. kind . descr ( ) ) ;
178185 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- ) ;
186+ if suggest_to_outer {
187+ err. span_suggestion_verbose (
188+ replacement_span,
189+ fluent:: parse_sugg_change_inner_to_outer,
190+ match attr_type {
191+ OuterAttributeType :: Attribute => "" ,
192+ OuterAttributeType :: DocBlockComment => "*" ,
193+ OuterAttributeType :: DocComment => "/" ,
194+ } ,
195+ rustc_errors:: Applicability :: MachineApplicable ,
196+ ) ;
197+ }
189198 return None ;
190199 }
191200 Err ( item_err) => {
@@ -196,7 +205,12 @@ impl<'a> Parser<'a> {
196205 Some ( replacement_span)
197206 }
198207
199- pub ( super ) fn error_on_forbidden_inner_attr ( & self , attr_sp : Span , policy : InnerAttrPolicy ) {
208+ pub ( super ) fn error_on_forbidden_inner_attr (
209+ & self ,
210+ attr_sp : Span ,
211+ policy : InnerAttrPolicy ,
212+ suggest_to_outer : bool ,
213+ ) {
200214 if let InnerAttrPolicy :: Forbidden ( reason) = policy {
201215 let mut diag = match reason. as_ref ( ) . copied ( ) {
202216 Some ( InnerAttrForbiddenReason :: AfterOuterDocComment { prev_doc_comment_span } ) => {
@@ -230,6 +244,7 @@ impl<'a> Parser<'a> {
230244 & mut diag,
231245 attr_sp,
232246 OuterAttributeType :: Attribute ,
247+ suggest_to_outer,
233248 )
234249 . is_some ( )
235250 {
0 commit comments