@@ -134,14 +134,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
134
134
Attribute :: Parsed ( AttributeKind :: ProcMacroAttribute ( _) ) => {
135
135
self . check_proc_macro ( hir_id, target, ProcMacroKind :: Attribute ) ;
136
136
}
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 { .. } ) => {
145
138
self . check_proc_macro ( hir_id, target, ProcMacroKind :: Derive )
146
139
}
147
140
Attribute :: Parsed (
@@ -164,9 +157,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
164
157
& Attribute :: Parsed ( AttributeKind :: TypeConst ( attr_span) ) => {
165
158
self . check_type_const ( hir_id, attr_span, target)
166
159
}
167
- & Attribute :: Parsed ( AttributeKind :: Marker ( attr_span) ) => {
168
- self . check_marker ( hir_id, attr_span, span, target)
169
- }
170
160
Attribute :: Parsed ( AttributeKind :: Fundamental | AttributeKind :: CoherenceIsCore ) => {
171
161
// FIXME: add validation
172
162
}
@@ -176,14 +166,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
176
166
Attribute :: Parsed ( AttributeKind :: Confusables { first_span, .. } ) => {
177
167
self . check_confusables ( * first_span, target) ;
178
168
}
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
- ) ,
187
169
Attribute :: Parsed (
188
170
AttributeKind :: Stability {
189
171
span : attr_span,
@@ -247,25 +229,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
247
229
Attribute :: Parsed ( AttributeKind :: MacroEscape ( span) ) => {
248
230
self . check_macro_use ( hir_id, sym:: macro_escape, * span, target)
249
231
}
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)
263
234
}
264
235
Attribute :: Parsed ( AttributeKind :: TrackCaller ( attr_span) ) => {
265
236
self . check_track_caller ( hir_id, * attr_span, attrs, span, target)
266
237
}
267
238
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)
269
240
}
270
241
Attribute :: Parsed (
271
242
AttributeKind :: RustcLayoutScalarValidRangeStart ( _num, attr_span)
@@ -289,7 +260,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
289
260
| AttributeKind :: MacroTransparency ( _)
290
261
| AttributeKind :: Pointee ( ..)
291
262
| AttributeKind :: Dummy
292
- | AttributeKind :: RustcBuiltinMacro { .. } ,
263
+ | AttributeKind :: RustcBuiltinMacro { .. }
264
+ | AttributeKind :: Ignore { .. }
265
+ | AttributeKind :: Path ( ..)
266
+ | AttributeKind :: NoImplicitPrelude ( ..)
267
+ | AttributeKind :: AutomaticallyDerived ( ..)
268
+ | AttributeKind :: Marker ( ..)
269
+ ,
293
270
) => { /* do nothing */ }
294
271
Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
295
272
self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
@@ -303,9 +280,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
303
280
Attribute :: Parsed ( AttributeKind :: MayDangle ( attr_span) ) => {
304
281
self . check_may_dangle ( hir_id, * attr_span)
305
282
}
306
- Attribute :: Parsed ( AttributeKind :: Ignore { span, .. } ) => {
307
- self . check_generic_attr ( hir_id, sym:: ignore, * span, target, Target :: Fn )
308
- }
309
283
Attribute :: Parsed ( AttributeKind :: MustUse { span, .. } ) => {
310
284
self . check_must_use ( hir_id, * span, target)
311
285
}
@@ -715,29 +689,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
715
689
}
716
690
}
717
691
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
-
739
692
/// 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 ) {
741
694
match target {
742
695
Target :: Fn
743
696
| Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => {
@@ -756,13 +709,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
756
709
. emit ( ) ;
757
710
}
758
711
}
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
+ _ => { }
766
713
}
767
714
}
768
715
@@ -846,7 +793,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
846
793
/// Checks if the `#[non_exhaustive]` attribute on an `item` is valid.
847
794
fn check_non_exhaustive (
848
795
& self ,
849
- hir_id : HirId ,
850
796
attr_span : Span ,
851
797
span : Span ,
852
798
target : Target ,
@@ -867,36 +813,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
867
813
} ) ;
868
814
}
869
815
}
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
+ _ => { }
900
817
}
901
818
}
902
819
0 commit comments