@@ -76,6 +76,7 @@ impl<'a> Parser<'a> {
76
76
token:: CommentKind :: Line => OuterAttributeType :: DocComment ,
77
77
token:: CommentKind :: Block => OuterAttributeType :: DocBlockComment ,
78
78
} ,
79
+ true ,
79
80
) {
80
81
err. note ( fluent:: parse_note) ;
81
82
err. span_suggestion_verbose (
@@ -139,7 +140,11 @@ impl<'a> Parser<'a> {
139
140
140
141
// Emit error if inner attribute is encountered and forbidden.
141
142
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
+ ) ;
143
148
}
144
149
145
150
Ok ( attr:: mk_attr_from_item ( & self . psess . attr_id_generator , item, None , style, attr_sp) )
@@ -151,6 +156,7 @@ impl<'a> Parser<'a> {
151
156
err : & mut Diag < ' _ > ,
152
157
span : Span ,
153
158
attr_type : OuterAttributeType ,
159
+ suggest_to_outer : bool ,
154
160
) -> Option < Span > {
155
161
let mut snapshot = self . create_snapshot_for_diagnostic ( ) ;
156
162
let lo = span. lo ( )
@@ -185,16 +191,18 @@ impl<'a> Parser<'a> {
185
191
// FIXME(#100717)
186
192
err. arg ( "item" , item. kind . descr ( ) ) ;
187
193
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
+ }
198
206
return None ;
199
207
}
200
208
Err ( item_err) => {
@@ -205,7 +213,12 @@ impl<'a> Parser<'a> {
205
213
Some ( replacement_span)
206
214
}
207
215
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
+ ) {
209
222
if let InnerAttrPolicy :: Forbidden ( reason) = policy {
210
223
let mut diag = match reason. as_ref ( ) . copied ( ) {
211
224
Some ( InnerAttrForbiddenReason :: AfterOuterDocComment { prev_doc_comment_span } ) => {
@@ -239,6 +252,7 @@ impl<'a> Parser<'a> {
239
252
& mut diag,
240
253
attr_sp,
241
254
OuterAttributeType :: Attribute ,
255
+ suggest_to_outer,
242
256
)
243
257
. is_some ( )
244
258
{
0 commit comments