1-
21use clippy_config:: Conf ;
32use clippy_config:: types:: { DisallowedPath , create_disallowed_map} ;
43use clippy_utils:: diagnostics:: { span_lint_and_then, span_lint_hir_and_then} ;
54use clippy_utils:: macros:: macro_backtrace;
65use clippy_utils:: paths:: PathNS ;
76use rustc_data_structures:: fx:: FxHashSet ;
7+ use rustc_hir:: attrs:: AttributeKind ;
88use rustc_hir:: def:: DefKind ;
99use rustc_hir:: def_id:: DefIdMap ;
1010use rustc_hir:: {
11- AmbigArg , Expr , ExprKind , ForeignItem , HirId , ImplItem , Item , ItemKind , OwnerId , Pat , Path , Stmt , TraitItem , Ty ,
11+ AmbigArg , Attribute , Expr , ExprKind , ForeignItem , HirId , ImplItem , Item , ItemKind , OwnerId , Pat , Path , Stmt ,
12+ TraitItem , Ty ,
1213} ;
1314use rustc_lint:: { LateContext , LateLintPass } ;
1415use rustc_middle:: ty:: TyCtxt ;
1516use rustc_session:: impl_lint_pass;
1617use rustc_span:: { ExpnId , MacroKind , Span } ;
1718
18- use crate :: utils:: attr_collector:: AttrStorage ;
19-
2019declare_clippy_lint ! {
2120 /// ### What it does
2221 /// Denies the configured macros in clippy.toml
@@ -69,14 +68,10 @@ pub struct DisallowedMacros {
6968 // Track the most recently seen node that can have a `derive` attribute.
7069 // Needed to use the correct lint level.
7170 derive_src : Option < OwnerId > ,
72-
73- // When a macro is disallowed in an early pass, it's stored
74- // and emitted during the late pass. This happens for attributes.
75- early_macro_cache : AttrStorage ,
7671}
7772
7873impl DisallowedMacros {
79- pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf , early_macro_cache : AttrStorage ) -> Self {
74+ pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
8075 let ( disallowed, _) = create_disallowed_map (
8176 tcx,
8277 & conf. disallowed_macros ,
@@ -89,7 +84,6 @@ impl DisallowedMacros {
8984 disallowed,
9085 seen : FxHashSet :: default ( ) ,
9186 derive_src : None ,
92- early_macro_cache,
9387 }
9488 }
9589
@@ -126,15 +120,87 @@ impl DisallowedMacros {
126120}
127121
128122impl_lint_pass ! ( DisallowedMacros => [ DISALLOWED_MACROS ] ) ;
129-
130123impl LateLintPass < ' _ > for DisallowedMacros {
131- fn check_crate ( & mut self , cx : & LateContext < ' _ > ) {
132- // once we check a crate in the late pass we can emit the early pass lints
133- if let Some ( attr_spans) = self . early_macro_cache . clone ( ) . 0 . get ( ) {
134- for span in attr_spans {
135- self . check ( cx, * span, None ) ;
136- }
137- }
124+ fn check_attribute ( & mut self , cx : & LateContext < ' _ > , attr : & Attribute ) {
125+ let span = match attr {
126+ Attribute :: Unparsed ( attr_item) => attr_item. span ,
127+ Attribute :: Parsed ( kind) => match kind {
128+ AttributeKind :: Align { span, .. }
129+ | AttributeKind :: AllowConstFnUnstable ( _, span)
130+ | AttributeKind :: AllowIncoherentImpl ( span)
131+ | AttributeKind :: AllowInternalUnstable ( _, span)
132+ | AttributeKind :: AsPtr ( span)
133+ | AttributeKind :: AutomaticallyDerived ( span)
134+ | AttributeKind :: BodyStability { span, .. }
135+ | AttributeKind :: Coinductive ( span)
136+ | AttributeKind :: Cold ( span)
137+ | AttributeKind :: Confusables { first_span : span, .. }
138+ | AttributeKind :: ConstContinue ( span)
139+ | AttributeKind :: ConstStability { span, .. }
140+ | AttributeKind :: ConstTrait ( span)
141+ | AttributeKind :: Coverage ( span, _)
142+ | AttributeKind :: DenyExplicitImpl ( span)
143+ | AttributeKind :: Deprecation { span, .. }
144+ | AttributeKind :: DoNotImplementViaObject ( span)
145+ | AttributeKind :: DocComment { span, .. }
146+ | AttributeKind :: ExportName { span, .. }
147+ | AttributeKind :: FfiConst ( span)
148+ | AttributeKind :: FfiPure ( span)
149+ | AttributeKind :: Ignore { span, .. }
150+ | AttributeKind :: Inline ( _, span)
151+ | AttributeKind :: LinkName { span, .. }
152+ | AttributeKind :: LinkOrdinal { span, .. }
153+ | AttributeKind :: LinkSection { span, .. }
154+ | AttributeKind :: LoopMatch ( span)
155+ | AttributeKind :: MacroEscape ( span)
156+ | AttributeKind :: MacroUse { span, .. }
157+ | AttributeKind :: Marker ( span)
158+ | AttributeKind :: MayDangle ( span)
159+ | AttributeKind :: MustUse { span, .. }
160+ | AttributeKind :: Naked ( span)
161+ | AttributeKind :: NoImplicitPrelude ( span)
162+ | AttributeKind :: NoMangle ( span)
163+ | AttributeKind :: NonExhaustive ( span)
164+ | AttributeKind :: Optimize ( _, span)
165+ | AttributeKind :: ParenSugar ( span)
166+ | AttributeKind :: PassByValue ( span)
167+ | AttributeKind :: Path ( _, span)
168+ | AttributeKind :: Pointee ( span)
169+ | AttributeKind :: ProcMacro ( span)
170+ | AttributeKind :: ProcMacroAttribute ( span)
171+ | AttributeKind :: ProcMacroDerive { span, .. }
172+ | AttributeKind :: PubTransparent ( span)
173+ | AttributeKind :: Repr { first_span : span, .. }
174+ | AttributeKind :: RustcBuiltinMacro { span, .. }
175+ | AttributeKind :: RustcLayoutScalarValidRangeEnd ( _, span)
176+ | AttributeKind :: RustcLayoutScalarValidRangeStart ( _, span)
177+ | AttributeKind :: SkipDuringMethodDispatch { span, .. }
178+ | AttributeKind :: SpecializationTrait ( span)
179+ | AttributeKind :: Stability { span, .. }
180+ | AttributeKind :: StdInternalSymbol ( span)
181+ | AttributeKind :: TargetFeature ( _, span)
182+ | AttributeKind :: TrackCaller ( span)
183+ | AttributeKind :: TypeConst ( span)
184+ | AttributeKind :: UnsafeSpecializationMarker ( span)
185+ | AttributeKind :: AllowInternalUnsafe ( span)
186+ | AttributeKind :: Coroutine ( span)
187+ | AttributeKind :: Linkage ( _, span)
188+ | AttributeKind :: ShouldPanic { span, .. }
189+ | AttributeKind :: Used { span, .. } => * span,
190+
191+ AttributeKind :: CoherenceIsCore
192+ | AttributeKind :: ConstStabilityIndirect
193+ | AttributeKind :: Dummy
194+ | AttributeKind :: ExportStable
195+ | AttributeKind :: Fundamental
196+ | AttributeKind :: MacroTransparency ( _)
197+ | AttributeKind :: RustcObjectLifetimeDefault
198+ | AttributeKind :: UnstableFeatureBound ( _) => {
199+ return ;
200+ } ,
201+ } ,
202+ } ;
203+ self . check ( cx, span, self . derive_src ) ;
138204 }
139205
140206 fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
0 commit comments