@@ -116,92 +116,96 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
116
116
let mut seen = FxHashMap :: default ( ) ;
117
117
let attrs = self . tcx . hir ( ) . attrs ( hir_id) ;
118
118
for attr in attrs {
119
- if attr. path_matches ( & [ sym:: diagnostic, sym:: on_unimplemented] ) {
120
- self . check_diagnostic_on_unimplemented ( attr. span , hir_id, target) ;
121
- }
122
- match attr. name_or_empty ( ) {
123
- sym:: do_not_recommend => self . check_do_not_recommend ( attr. span , target) ,
124
- sym:: inline => self . check_inline ( hir_id, attr, span, target) ,
125
- sym:: coverage => self . check_coverage ( hir_id, attr, span, target) ,
126
- sym:: non_exhaustive => self . check_non_exhaustive ( hir_id, attr, span, target) ,
127
- sym:: marker => self . check_marker ( hir_id, attr, span, target) ,
128
- sym:: target_feature => self . check_target_feature ( hir_id, attr, span, target, attrs) ,
129
- sym:: thread_local => self . check_thread_local ( attr, span, target) ,
130
- sym:: track_caller => {
119
+ match attr. path ( ) . as_slice ( ) {
120
+ [ sym:: diagnostic, sym:: do_not_recommend] => {
121
+ self . check_do_not_recommend ( attr. span , hir_id, target)
122
+ }
123
+ [ sym:: diagnostic, sym:: on_unimplemented] => {
124
+ self . check_diagnostic_on_unimplemented ( attr. span , hir_id, target)
125
+ }
126
+ [ sym:: inline] => self . check_inline ( hir_id, attr, span, target) ,
127
+ [ sym:: coverage] => self . check_coverage ( hir_id, attr, span, target) ,
128
+ [ sym:: non_exhaustive] => self . check_non_exhaustive ( hir_id, attr, span, target) ,
129
+ [ sym:: marker] => self . check_marker ( hir_id, attr, span, target) ,
130
+ [ sym:: target_feature] => {
131
+ self . check_target_feature ( hir_id, attr, span, target, attrs)
132
+ }
133
+ [ sym:: thread_local] => self . check_thread_local ( attr, span, target) ,
134
+ [ sym:: track_caller] => {
131
135
self . check_track_caller ( hir_id, attr. span , attrs, span, target)
132
136
}
133
- sym:: doc => self . check_doc_attrs (
137
+ [ sym:: doc] => self . check_doc_attrs (
134
138
attr,
135
139
hir_id,
136
140
target,
137
141
& mut specified_inline,
138
142
& mut doc_aliases,
139
143
) ,
140
- sym:: no_link => self . check_no_link ( hir_id, attr, span, target) ,
141
- sym:: export_name => self . check_export_name ( hir_id, attr, span, target) ,
142
- sym:: rustc_layout_scalar_valid_range_start
143
- | sym:: rustc_layout_scalar_valid_range_end => {
144
+ [ sym:: no_link] => self . check_no_link ( hir_id, attr, span, target) ,
145
+ [ sym:: export_name] => self . check_export_name ( hir_id, attr, span, target) ,
146
+ [ sym:: rustc_layout_scalar_valid_range_start]
147
+ | [ sym:: rustc_layout_scalar_valid_range_end] => {
144
148
self . check_rustc_layout_scalar_valid_range ( attr, span, target)
145
149
}
146
- sym:: allow_internal_unstable => {
150
+ [ sym:: allow_internal_unstable] => {
147
151
self . check_allow_internal_unstable ( hir_id, attr, span, target, attrs)
148
152
}
149
- sym:: debugger_visualizer => self . check_debugger_visualizer ( attr, target) ,
150
- sym:: rustc_allow_const_fn_unstable => {
153
+ [ sym:: debugger_visualizer] => self . check_debugger_visualizer ( attr, target) ,
154
+ [ sym:: rustc_allow_const_fn_unstable] => {
151
155
self . check_rustc_allow_const_fn_unstable ( hir_id, attr, span, target)
152
156
}
153
- sym:: rustc_std_internal_symbol => {
157
+ [ sym:: rustc_std_internal_symbol] => {
154
158
self . check_rustc_std_internal_symbol ( attr, span, target)
155
159
}
156
- sym:: naked => self . check_naked ( hir_id, attr, span, target) ,
157
- sym:: rustc_never_returns_null_ptr => {
160
+ [ sym:: naked] => self . check_naked ( hir_id, attr, span, target) ,
161
+ [ sym:: rustc_never_returns_null_ptr] => {
158
162
self . check_applied_to_fn_or_method ( hir_id, attr, span, target)
159
163
}
160
- sym:: rustc_legacy_const_generics => {
164
+ [ sym:: rustc_legacy_const_generics] => {
161
165
self . check_rustc_legacy_const_generics ( hir_id, attr, span, target, item)
162
166
}
163
- sym:: rustc_lint_query_instability => {
167
+ [ sym:: rustc_lint_query_instability] => {
164
168
self . check_rustc_lint_query_instability ( hir_id, attr, span, target)
165
169
}
166
- sym:: rustc_lint_diagnostics => {
170
+ [ sym:: rustc_lint_diagnostics] => {
167
171
self . check_rustc_lint_diagnostics ( hir_id, attr, span, target)
168
172
}
169
- sym:: rustc_lint_opt_ty => self . check_rustc_lint_opt_ty ( attr, span, target) ,
170
- sym:: rustc_lint_opt_deny_field_access => {
173
+ [ sym:: rustc_lint_opt_ty] => self . check_rustc_lint_opt_ty ( attr, span, target) ,
174
+ [ sym:: rustc_lint_opt_deny_field_access] => {
171
175
self . check_rustc_lint_opt_deny_field_access ( attr, span, target)
172
176
}
173
- sym:: rustc_clean
174
- | sym:: rustc_dirty
175
- | sym:: rustc_if_this_changed
176
- | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( attr) ,
177
- sym:: rustc_coinductive
178
- | sym:: rustc_must_implement_one_of
179
- | sym:: rustc_deny_explicit_impl
180
- | sym:: const_trait => self . check_must_be_applied_to_trait ( attr, span, target) ,
181
- sym:: cmse_nonsecure_entry => {
177
+ [ sym:: rustc_clean]
178
+ | [ sym:: rustc_dirty]
179
+ | [ sym:: rustc_if_this_changed]
180
+ | [ sym:: rustc_then_this_would_need] => self . check_rustc_dirty_clean ( attr) ,
181
+ [ sym:: rustc_coinductive]
182
+ | [ sym:: rustc_must_implement_one_of]
183
+ | [ sym:: rustc_deny_explicit_impl]
184
+ | [ sym:: const_trait] => self . check_must_be_applied_to_trait ( attr, span, target) ,
185
+ [ sym:: cmse_nonsecure_entry] => {
182
186
self . check_cmse_nonsecure_entry ( hir_id, attr, span, target)
183
187
}
184
- sym:: collapse_debuginfo => self . check_collapse_debuginfo ( attr, span, target) ,
185
- sym:: must_not_suspend => self . check_must_not_suspend ( attr, span, target) ,
186
- sym:: must_use => self . check_must_use ( hir_id, attr, target) ,
187
- sym:: rustc_pass_by_value => self . check_pass_by_value ( attr, span, target) ,
188
- sym:: rustc_allow_incoherent_impl => {
188
+ [ sym:: collapse_debuginfo] => self . check_collapse_debuginfo ( attr, span, target) ,
189
+ [ sym:: must_not_suspend] => self . check_must_not_suspend ( attr, span, target) ,
190
+ [ sym:: must_use] => self . check_must_use ( hir_id, attr, target) ,
191
+ [ sym:: rustc_pass_by_value] => self . check_pass_by_value ( attr, span, target) ,
192
+ [ sym:: rustc_allow_incoherent_impl] => {
189
193
self . check_allow_incoherent_impl ( attr, span, target)
190
194
}
191
- sym:: rustc_has_incoherent_inherent_impls => {
195
+ [ sym:: rustc_has_incoherent_inherent_impls] => {
192
196
self . check_has_incoherent_inherent_impls ( attr, span, target)
193
197
}
194
- sym:: ffi_pure => self . check_ffi_pure ( attr. span , attrs, target) ,
195
- sym:: ffi_const => self . check_ffi_const ( attr. span , target) ,
196
- sym:: rustc_const_unstable
197
- | sym:: rustc_const_stable
198
- | sym:: unstable
199
- | sym:: stable
200
- | sym:: rustc_allowed_through_unstable_modules
201
- | sym:: rustc_promotable => self . check_stability_promotable ( attr, target) ,
202
- sym:: link_ordinal => self . check_link_ordinal ( attr, span, target) ,
203
- sym:: rustc_confusables => self . check_confusables ( attr, target) ,
204
- sym:: rustc_safe_intrinsic => {
198
+ [ sym:: ffi_pure] => self . check_ffi_pure ( attr. span , attrs, target) ,
199
+ [ sym:: ffi_const] => self . check_ffi_const ( attr. span , target) ,
200
+ [ sym:: rustc_const_unstable]
201
+ | [ sym:: rustc_const_stable]
202
+ | [ sym:: unstable]
203
+ | [ sym:: stable]
204
+ | [ sym:: rustc_allowed_through_unstable_modules]
205
+ | [ sym:: rustc_promotable] => self . check_stability_promotable ( attr, target) ,
206
+ [ sym:: link_ordinal] => self . check_link_ordinal ( attr, span, target) ,
207
+ [ sym:: rustc_confusables] => self . check_confusables ( attr, target) ,
208
+ [ sym:: rustc_safe_intrinsic] => {
205
209
self . check_rustc_safe_intrinsic ( hir_id, attr, span, target)
206
210
}
207
211
_ => true ,
@@ -293,18 +297,26 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
293
297
) ;
294
298
}
295
299
296
- /// Checks if `#[do_not_recommend]` is applied on a trait impl.
297
- fn check_do_not_recommend ( & self , attr_span : Span , target : Target ) -> bool {
298
- if let Target :: Impl = target {
299
- true
300
- } else {
301
- self . dcx ( ) . emit_err ( errors:: IncorrectDoNotRecommendLocation { span : attr_span } ) ;
302
- false
300
+ /// Checks if `#[diagnostic::do_not_recommend]` is applied on a trait impl.
301
+ fn check_do_not_recommend ( & self , attr_span : Span , hir_id : HirId , target : Target ) -> bool {
302
+ if !matches ! ( target, Target :: Impl ) {
303
+ self . tcx . emit_node_span_lint (
304
+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
305
+ hir_id,
306
+ attr_span,
307
+ errors:: IncorrectDoNotRecommendLocation ,
308
+ ) ;
303
309
}
310
+ true
304
311
}
305
312
306
313
/// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition
307
- fn check_diagnostic_on_unimplemented ( & self , attr_span : Span , hir_id : HirId , target : Target ) {
314
+ fn check_diagnostic_on_unimplemented (
315
+ & self ,
316
+ attr_span : Span ,
317
+ hir_id : HirId ,
318
+ target : Target ,
319
+ ) -> bool {
308
320
if !matches ! ( target, Target :: Trait ) {
309
321
self . tcx . emit_node_span_lint (
310
322
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
@@ -313,6 +325,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
313
325
DiagnosticOnUnimplementedOnlyForTraits ,
314
326
) ;
315
327
}
328
+ true
316
329
}
317
330
318
331
/// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
0 commit comments