@@ -113,92 +113,96 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
113113 let mut seen = FxHashMap :: default ( ) ;
114114 let attrs = self . tcx . hir ( ) . attrs ( hir_id) ;
115115 for attr in attrs {
116- if attr. path_matches ( & [ sym:: diagnostic, sym:: on_unimplemented] ) {
117- self . check_diagnostic_on_unimplemented ( attr. span , hir_id, target) ;
118- }
119- match attr. name_or_empty ( ) {
120- sym:: do_not_recommend => self . check_do_not_recommend ( attr. span , target) ,
121- sym:: inline => self . check_inline ( hir_id, attr, span, target) ,
122- sym:: coverage => self . check_coverage ( hir_id, attr, span, target) ,
123- sym:: non_exhaustive => self . check_non_exhaustive ( hir_id, attr, span, target) ,
124- sym:: marker => self . check_marker ( hir_id, attr, span, target) ,
125- sym:: target_feature => self . check_target_feature ( hir_id, attr, span, target, attrs) ,
126- sym:: thread_local => self . check_thread_local ( attr, span, target) ,
127- sym:: track_caller => {
116+ match attr. path ( ) . as_slice ( ) {
117+ [ sym:: diagnostic, sym:: do_not_recommend] => {
118+ self . check_do_not_recommend ( attr. span , hir_id, target)
119+ }
120+ [ sym:: diagnostic, sym:: on_unimplemented] => {
121+ self . check_diagnostic_on_unimplemented ( attr. span , hir_id, target)
122+ }
123+ [ sym:: inline] => self . check_inline ( hir_id, attr, span, target) ,
124+ [ sym:: coverage] => self . check_coverage ( hir_id, attr, span, target) ,
125+ [ sym:: non_exhaustive] => self . check_non_exhaustive ( hir_id, attr, span, target) ,
126+ [ sym:: marker] => self . check_marker ( hir_id, attr, span, target) ,
127+ [ sym:: target_feature] => {
128+ self . check_target_feature ( hir_id, attr, span, target, attrs)
129+ }
130+ [ sym:: thread_local] => self . check_thread_local ( attr, span, target) ,
131+ [ sym:: track_caller] => {
128132 self . check_track_caller ( hir_id, attr. span , attrs, span, target)
129133 }
130- sym:: doc => self . check_doc_attrs (
134+ [ sym:: doc] => self . check_doc_attrs (
131135 attr,
132136 hir_id,
133137 target,
134138 & mut specified_inline,
135139 & mut doc_aliases,
136140 ) ,
137- sym:: no_link => self . check_no_link ( hir_id, attr, span, target) ,
138- sym:: export_name => self . check_export_name ( hir_id, attr, span, target) ,
139- sym:: rustc_layout_scalar_valid_range_start
140- | sym:: rustc_layout_scalar_valid_range_end => {
141+ [ sym:: no_link] => self . check_no_link ( hir_id, attr, span, target) ,
142+ [ sym:: export_name] => self . check_export_name ( hir_id, attr, span, target) ,
143+ [ sym:: rustc_layout_scalar_valid_range_start]
144+ | [ sym:: rustc_layout_scalar_valid_range_end] => {
141145 self . check_rustc_layout_scalar_valid_range ( attr, span, target)
142146 }
143- sym:: allow_internal_unstable => {
147+ [ sym:: allow_internal_unstable] => {
144148 self . check_allow_internal_unstable ( hir_id, attr, span, target, attrs)
145149 }
146- sym:: debugger_visualizer => self . check_debugger_visualizer ( attr, target) ,
147- sym:: rustc_allow_const_fn_unstable => {
150+ [ sym:: debugger_visualizer] => self . check_debugger_visualizer ( attr, target) ,
151+ [ sym:: rustc_allow_const_fn_unstable] => {
148152 self . check_rustc_allow_const_fn_unstable ( hir_id, attr, span, target)
149153 }
150- sym:: rustc_std_internal_symbol => {
154+ [ sym:: rustc_std_internal_symbol] => {
151155 self . check_rustc_std_internal_symbol ( attr, span, target)
152156 }
153- sym:: naked => self . check_naked ( hir_id, attr, span, target) ,
154- sym:: rustc_never_returns_null_ptr => {
157+ [ sym:: naked] => self . check_naked ( hir_id, attr, span, target) ,
158+ [ sym:: rustc_never_returns_null_ptr] => {
155159 self . check_applied_to_fn_or_method ( hir_id, attr, span, target)
156160 }
157- sym:: rustc_legacy_const_generics => {
161+ [ sym:: rustc_legacy_const_generics] => {
158162 self . check_rustc_legacy_const_generics ( hir_id, attr, span, target, item)
159163 }
160- sym:: rustc_lint_query_instability => {
164+ [ sym:: rustc_lint_query_instability] => {
161165 self . check_rustc_lint_query_instability ( hir_id, attr, span, target)
162166 }
163- sym:: rustc_lint_diagnostics => {
167+ [ sym:: rustc_lint_diagnostics] => {
164168 self . check_rustc_lint_diagnostics ( hir_id, attr, span, target)
165169 }
166- sym:: rustc_lint_opt_ty => self . check_rustc_lint_opt_ty ( attr, span, target) ,
167- sym:: rustc_lint_opt_deny_field_access => {
170+ [ sym:: rustc_lint_opt_ty] => self . check_rustc_lint_opt_ty ( attr, span, target) ,
171+ [ sym:: rustc_lint_opt_deny_field_access] => {
168172 self . check_rustc_lint_opt_deny_field_access ( attr, span, target)
169173 }
170- sym:: rustc_clean
171- | sym:: rustc_dirty
172- | sym:: rustc_if_this_changed
173- | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( attr) ,
174- sym:: rustc_coinductive
175- | sym:: rustc_must_implement_one_of
176- | sym:: rustc_deny_explicit_impl
177- | sym:: const_trait => self . check_must_be_applied_to_trait ( attr, span, target) ,
178- sym:: cmse_nonsecure_entry => {
174+ [ sym:: rustc_clean]
175+ | [ sym:: rustc_dirty]
176+ | [ sym:: rustc_if_this_changed]
177+ | [ sym:: rustc_then_this_would_need] => self . check_rustc_dirty_clean ( attr) ,
178+ [ sym:: rustc_coinductive]
179+ | [ sym:: rustc_must_implement_one_of]
180+ | [ sym:: rustc_deny_explicit_impl]
181+ | [ sym:: const_trait] => self . check_must_be_applied_to_trait ( attr, span, target) ,
182+ [ sym:: cmse_nonsecure_entry] => {
179183 self . check_cmse_nonsecure_entry ( hir_id, attr, span, target)
180184 }
181- sym:: collapse_debuginfo => self . check_collapse_debuginfo ( attr, span, target) ,
182- sym:: must_not_suspend => self . check_must_not_suspend ( attr, span, target) ,
183- sym:: must_use => self . check_must_use ( hir_id, attr, target) ,
184- sym:: rustc_pass_by_value => self . check_pass_by_value ( attr, span, target) ,
185- sym:: rustc_allow_incoherent_impl => {
185+ [ sym:: collapse_debuginfo] => self . check_collapse_debuginfo ( attr, span, target) ,
186+ [ sym:: must_not_suspend] => self . check_must_not_suspend ( attr, span, target) ,
187+ [ sym:: must_use] => self . check_must_use ( hir_id, attr, target) ,
188+ [ sym:: rustc_pass_by_value] => self . check_pass_by_value ( attr, span, target) ,
189+ [ sym:: rustc_allow_incoherent_impl] => {
186190 self . check_allow_incoherent_impl ( attr, span, target)
187191 }
188- sym:: rustc_has_incoherent_inherent_impls => {
192+ [ sym:: rustc_has_incoherent_inherent_impls] => {
189193 self . check_has_incoherent_inherent_impls ( attr, span, target)
190194 }
191- sym:: ffi_pure => self . check_ffi_pure ( attr. span , attrs, target) ,
192- sym:: ffi_const => self . check_ffi_const ( attr. span , target) ,
193- sym:: rustc_const_unstable
194- | sym:: rustc_const_stable
195- | sym:: unstable
196- | sym:: stable
197- | sym:: rustc_allowed_through_unstable_modules
198- | sym:: rustc_promotable => self . check_stability_promotable ( attr, target) ,
199- sym:: link_ordinal => self . check_link_ordinal ( attr, span, target) ,
200- sym:: rustc_confusables => self . check_confusables ( attr, target) ,
201- sym:: rustc_safe_intrinsic => {
195+ [ sym:: ffi_pure] => self . check_ffi_pure ( attr. span , attrs, target) ,
196+ [ sym:: ffi_const] => self . check_ffi_const ( attr. span , target) ,
197+ [ sym:: rustc_const_unstable]
198+ | [ sym:: rustc_const_stable]
199+ | [ sym:: unstable]
200+ | [ sym:: stable]
201+ | [ sym:: rustc_allowed_through_unstable_modules]
202+ | [ sym:: rustc_promotable] => self . check_stability_promotable ( attr, target) ,
203+ [ sym:: link_ordinal] => self . check_link_ordinal ( attr, span, target) ,
204+ [ sym:: rustc_confusables] => self . check_confusables ( attr, target) ,
205+ [ sym:: rustc_safe_intrinsic] => {
202206 self . check_rustc_safe_intrinsic ( hir_id, attr, span, target)
203207 }
204208 _ => true ,
@@ -290,18 +294,26 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
290294 ) ;
291295 }
292296
293- /// Checks if `#[do_not_recommend]` is applied on a trait impl.
294- fn check_do_not_recommend ( & self , attr_span : Span , target : Target ) -> bool {
295- if let Target :: Impl = target {
296- true
297- } else {
298- self . dcx ( ) . emit_err ( errors:: IncorrectDoNotRecommendLocation { span : attr_span } ) ;
299- false
297+ /// Checks if `#[diagnostic::do_not_recommend]` is applied on a trait impl.
298+ fn check_do_not_recommend ( & self , attr_span : Span , hir_id : HirId , target : Target ) -> bool {
299+ if !matches ! ( target, Target :: Impl ) {
300+ self . tcx . emit_node_span_lint (
301+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
302+ hir_id,
303+ attr_span,
304+ errors:: IncorrectDoNotRecommendLocation ,
305+ ) ;
300306 }
307+ true
301308 }
302309
303310 /// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition
304- fn check_diagnostic_on_unimplemented ( & self , attr_span : Span , hir_id : HirId , target : Target ) {
311+ fn check_diagnostic_on_unimplemented (
312+ & self ,
313+ attr_span : Span ,
314+ hir_id : HirId ,
315+ target : Target ,
316+ ) -> bool {
305317 if !matches ! ( target, Target :: Trait ) {
306318 self . tcx . emit_node_span_lint (
307319 UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
@@ -310,6 +322,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
310322 DiagnosticOnUnimplementedOnlyForTraits ,
311323 ) ;
312324 }
325+ true
313326 }
314327
315328 /// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
0 commit comments