@@ -116,92 +116,96 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
116116 let mut seen = FxHashMap :: default ( ) ;
117117 let attrs = self . tcx . hir ( ) . attrs ( hir_id) ;
118118 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] => {
131135 self . check_track_caller ( hir_id, attr. span , attrs, span, target)
132136 }
133- sym:: doc => self . check_doc_attrs (
137+ [ sym:: doc] => self . check_doc_attrs (
134138 attr,
135139 hir_id,
136140 target,
137141 & mut specified_inline,
138142 & mut doc_aliases,
139143 ) ,
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] => {
144148 self . check_rustc_layout_scalar_valid_range ( attr, span, target)
145149 }
146- sym:: allow_internal_unstable => {
150+ [ sym:: allow_internal_unstable] => {
147151 self . check_allow_internal_unstable ( hir_id, attr, span, target, attrs)
148152 }
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] => {
151155 self . check_rustc_allow_const_fn_unstable ( hir_id, attr, span, target)
152156 }
153- sym:: rustc_std_internal_symbol => {
157+ [ sym:: rustc_std_internal_symbol] => {
154158 self . check_rustc_std_internal_symbol ( attr, span, target)
155159 }
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] => {
158162 self . check_applied_to_fn_or_method ( hir_id, attr, span, target)
159163 }
160- sym:: rustc_legacy_const_generics => {
164+ [ sym:: rustc_legacy_const_generics] => {
161165 self . check_rustc_legacy_const_generics ( hir_id, attr, span, target, item)
162166 }
163- sym:: rustc_lint_query_instability => {
167+ [ sym:: rustc_lint_query_instability] => {
164168 self . check_rustc_lint_query_instability ( hir_id, attr, span, target)
165169 }
166- sym:: rustc_lint_diagnostics => {
170+ [ sym:: rustc_lint_diagnostics] => {
167171 self . check_rustc_lint_diagnostics ( hir_id, attr, span, target)
168172 }
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] => {
171175 self . check_rustc_lint_opt_deny_field_access ( attr, span, target)
172176 }
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] => {
182186 self . check_cmse_nonsecure_entry ( hir_id, attr, span, target)
183187 }
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] => {
189193 self . check_allow_incoherent_impl ( attr, span, target)
190194 }
191- sym:: rustc_has_incoherent_inherent_impls => {
195+ [ sym:: rustc_has_incoherent_inherent_impls] => {
192196 self . check_has_incoherent_inherent_impls ( attr, span, target)
193197 }
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] => {
205209 self . check_rustc_safe_intrinsic ( hir_id, attr, span, target)
206210 }
207211 _ => true ,
@@ -293,18 +297,26 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
293297 ) ;
294298 }
295299
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+ ) ;
303309 }
310+ true
304311 }
305312
306313 /// 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 {
308320 if !matches ! ( target, Target :: Trait ) {
309321 self . tcx . emit_node_span_lint (
310322 UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
@@ -313,6 +325,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
313325 DiagnosticOnUnimplementedOnlyForTraits ,
314326 ) ;
315327 }
328+ true
316329 }
317330
318331 /// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
0 commit comments