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