@@ -67,6 +67,7 @@ impl<'a> Parser<'a> {
67
67
token:: CommentKind :: Line => OuterAttributeType :: DocComment ,
68
68
token:: CommentKind :: Block => OuterAttributeType :: DocBlockComment ,
69
69
} ,
70
+ true ,
70
71
) {
71
72
err. note ( fluent:: parse_note) ;
72
73
err. span_suggestion_verbose (
@@ -130,7 +131,11 @@ impl<'a> Parser<'a> {
130
131
131
132
// Emit error if inner attribute is encountered and forbidden.
132
133
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
+ ) ;
134
139
}
135
140
136
141
Ok ( attr:: mk_attr_from_item ( & self . psess . attr_id_generator , item, None , style, attr_sp) )
@@ -142,6 +147,7 @@ impl<'a> Parser<'a> {
142
147
err : & mut Diag < ' _ > ,
143
148
span : Span ,
144
149
attr_type : OuterAttributeType ,
150
+ suggest_to_outer : bool ,
145
151
) -> Option < Span > {
146
152
let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
147
153
let lo = span. lo ( )
@@ -176,16 +182,18 @@ impl<'a> Parser<'a> {
176
182
// FIXME(#100717)
177
183
err. arg ( "item" , item. kind . descr ( ) ) ;
178
184
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
+ }
189
197
return None ;
190
198
}
191
199
Err ( item_err) => {
@@ -196,7 +204,12 @@ impl<'a> Parser<'a> {
196
204
Some ( replacement_span)
197
205
}
198
206
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
+ ) {
200
213
if let InnerAttrPolicy :: Forbidden ( reason) = policy {
201
214
let mut diag = match reason. as_ref ( ) . copied ( ) {
202
215
Some ( InnerAttrForbiddenReason :: AfterOuterDocComment { prev_doc_comment_span } ) => {
@@ -230,6 +243,7 @@ impl<'a> Parser<'a> {
230
243
& mut diag,
231
244
attr_sp,
232
245
OuterAttributeType :: Attribute ,
246
+ suggest_to_outer,
233
247
)
234
248
. is_some ( )
235
249
{
0 commit comments