@@ -134,14 +134,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
134134 Attribute :: Parsed ( AttributeKind :: ProcMacroAttribute ( _) ) => {
135135 self . check_proc_macro ( hir_id, target, ProcMacroKind :: Attribute ) ;
136136 }
137- Attribute :: Parsed ( AttributeKind :: ProcMacroDerive { span : attr_span, .. } ) => {
138- self . check_generic_attr (
139- hir_id,
140- sym:: proc_macro_derive,
141- * attr_span,
142- target,
143- Target :: Fn ,
144- ) ;
137+ Attribute :: Parsed ( AttributeKind :: ProcMacroDerive { .. } ) => {
145138 self . check_proc_macro ( hir_id, target, ProcMacroKind :: Derive )
146139 }
147140 Attribute :: Parsed (
@@ -164,9 +157,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
164157 & Attribute :: Parsed ( AttributeKind :: TypeConst ( attr_span) ) => {
165158 self . check_type_const ( hir_id, attr_span, target)
166159 }
167- & Attribute :: Parsed ( AttributeKind :: Marker ( attr_span) ) => {
168- self . check_marker ( hir_id, attr_span, span, target)
169- }
170160 Attribute :: Parsed ( AttributeKind :: Fundamental | AttributeKind :: CoherenceIsCore ) => {
171161 // FIXME: add validation
172162 }
@@ -176,14 +166,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
176166 Attribute :: Parsed ( AttributeKind :: Confusables { first_span, .. } ) => {
177167 self . check_confusables ( * first_span, target) ;
178168 }
179- Attribute :: Parsed ( AttributeKind :: AutomaticallyDerived ( attr_span) ) => self
180- . check_generic_attr (
181- hir_id,
182- sym:: automatically_derived,
183- * attr_span,
184- target,
185- Target :: Impl { of_trait : true } ,
186- ) ,
187169 Attribute :: Parsed (
188170 AttributeKind :: Stability {
189171 span : attr_span,
@@ -247,25 +229,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
247229 Attribute :: Parsed ( AttributeKind :: MacroEscape ( span) ) => {
248230 self . check_macro_use ( hir_id, sym:: macro_escape, * span, target)
249231 }
250- Attribute :: Parsed ( AttributeKind :: Naked ( attr_span) ) => {
251- self . check_naked ( hir_id, * attr_span, span, target)
252- }
253- Attribute :: Parsed ( AttributeKind :: NoImplicitPrelude ( attr_span) ) => self
254- . check_generic_attr (
255- hir_id,
256- sym:: no_implicit_prelude,
257- * attr_span,
258- target,
259- Target :: Mod ,
260- ) ,
261- Attribute :: Parsed ( AttributeKind :: Path ( _, attr_span) ) => {
262- self . check_generic_attr ( hir_id, sym:: path, * attr_span, target, Target :: Mod )
232+ Attribute :: Parsed ( AttributeKind :: Naked ( ..) ) => {
233+ self . check_naked ( hir_id, target)
263234 }
264235 Attribute :: Parsed ( AttributeKind :: TrackCaller ( attr_span) ) => {
265236 self . check_track_caller ( hir_id, * attr_span, attrs, span, target)
266237 }
267238 Attribute :: Parsed ( AttributeKind :: NonExhaustive ( attr_span) ) => {
268- self . check_non_exhaustive ( hir_id , * attr_span, span, target, item)
239+ self . check_non_exhaustive ( * attr_span, span, target, item)
269240 }
270241 Attribute :: Parsed (
271242 AttributeKind :: RustcLayoutScalarValidRangeStart ( _num, attr_span)
@@ -289,7 +260,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
289260 | AttributeKind :: MacroTransparency ( _)
290261 | AttributeKind :: Pointee ( ..)
291262 | AttributeKind :: Dummy
292- | AttributeKind :: RustcBuiltinMacro { .. } ,
263+ | AttributeKind :: RustcBuiltinMacro { .. }
264+ | AttributeKind :: Ignore { .. }
265+ | AttributeKind :: Path ( ..)
266+ | AttributeKind :: NoImplicitPrelude ( ..)
267+ | AttributeKind :: AutomaticallyDerived ( ..)
268+ | AttributeKind :: Marker ( ..)
269+ ,
293270 ) => { /* do nothing */ }
294271 Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
295272 self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
@@ -303,9 +280,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303280 Attribute :: Parsed ( AttributeKind :: MayDangle ( attr_span) ) => {
304281 self . check_may_dangle ( hir_id, * attr_span)
305282 }
306- Attribute :: Parsed ( AttributeKind :: Ignore { span, .. } ) => {
307- self . check_generic_attr ( hir_id, sym:: ignore, * span, target, Target :: Fn )
308- }
309283 Attribute :: Parsed ( AttributeKind :: MustUse { span, .. } ) => {
310284 self . check_must_use ( hir_id, * span, target)
311285 }
@@ -715,29 +689,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
715689 }
716690 }
717691
718- fn check_generic_attr (
719- & self ,
720- hir_id : HirId ,
721- attr_name : Symbol ,
722- attr_span : Span ,
723- target : Target ,
724- allowed_target : Target ,
725- ) {
726- if target != allowed_target {
727- self . tcx . emit_node_span_lint (
728- UNUSED_ATTRIBUTES ,
729- hir_id,
730- attr_span,
731- errors:: OnlyHasEffectOn {
732- attr_name : attr_name. to_string ( ) ,
733- target_name : allowed_target. name ( ) . replace ( ' ' , "_" ) ,
734- } ,
735- ) ;
736- }
737- }
738-
739692 /// Checks if `#[naked]` is applied to a function definition.
740- fn check_naked ( & self , hir_id : HirId , attr_span : Span , span : Span , target : Target ) {
693+ fn check_naked ( & self , hir_id : HirId , target : Target ) {
741694 match target {
742695 Target :: Fn
743696 | Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => {
@@ -756,13 +709,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
756709 . emit ( ) ;
757710 }
758711 }
759- _ => {
760- self . dcx ( ) . emit_err ( errors:: AttrShouldBeAppliedToFn {
761- attr_span,
762- defn_span : span,
763- on_crate : hir_id == CRATE_HIR_ID ,
764- } ) ;
765- }
712+ _ => { }
766713 }
767714 }
768715
@@ -846,7 +793,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
846793 /// Checks if the `#[non_exhaustive]` attribute on an `item` is valid.
847794 fn check_non_exhaustive (
848795 & self ,
849- hir_id : HirId ,
850796 attr_span : Span ,
851797 span : Span ,
852798 target : Target ,
@@ -867,36 +813,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
867813 } ) ;
868814 }
869815 }
870- Target :: Enum | Target :: Variant => { }
871- // FIXME(#80564): We permit struct fields, match arms and macro defs to have an
872- // `#[non_exhaustive]` attribute with just a lint, because we previously
873- // erroneously allowed it and some crates used it accidentally, to be compatible
874- // with crates depending on them, we can't throw an error here.
875- Target :: Field | Target :: Arm | Target :: MacroDef => {
876- self . inline_attr_str_error_with_macro_def ( hir_id, attr_span, "non_exhaustive" ) ;
877- }
878- _ => {
879- self . dcx ( )
880- . emit_err ( errors:: NonExhaustiveWrongLocation { attr_span, defn_span : span } ) ;
881- }
882- }
883- }
884-
885- /// Checks if the `#[marker]` attribute on an `item` is valid.
886- fn check_marker ( & self , hir_id : HirId , attr_span : Span , span : Span , target : Target ) {
887- match target {
888- Target :: Trait => { }
889- // FIXME(#80564): We permit struct fields, match arms and macro defs to have an
890- // `#[marker]` attribute with just a lint, because we previously
891- // erroneously allowed it and some crates used it accidentally, to be compatible
892- // with crates depending on them, we can't throw an error here.
893- Target :: Field | Target :: Arm | Target :: MacroDef => {
894- self . inline_attr_str_error_with_macro_def ( hir_id, attr_span, "marker" ) ;
895- }
896- _ => {
897- self . dcx ( )
898- . emit_err ( errors:: AttrShouldBeAppliedToTrait { attr_span, defn_span : span } ) ;
899- }
816+ _ => { }
900817 }
901818 }
902819
0 commit comments