@@ -4,18 +4,18 @@ use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
4
4
use clippy_utils:: macros:: macro_backtrace;
5
5
use clippy_utils:: paths:: PathNS ;
6
6
use rustc_data_structures:: fx:: FxHashSet ;
7
+ use rustc_hir:: attrs:: AttributeKind ;
7
8
use rustc_hir:: def:: DefKind ;
8
9
use rustc_hir:: def_id:: DefIdMap ;
9
10
use rustc_hir:: {
10
- 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 ,
11
13
} ;
12
14
use rustc_lint:: { LateContext , LateLintPass } ;
13
15
use rustc_middle:: ty:: TyCtxt ;
14
16
use rustc_session:: impl_lint_pass;
15
17
use rustc_span:: { ExpnId , MacroKind , Span } ;
16
18
17
- use crate :: utils:: attr_collector:: AttrStorage ;
18
-
19
19
declare_clippy_lint ! {
20
20
/// ### What it does
21
21
/// Denies the configured macros in clippy.toml
@@ -68,14 +68,10 @@ pub struct DisallowedMacros {
68
68
// Track the most recently seen node that can have a `derive` attribute.
69
69
// Needed to use the correct lint level.
70
70
derive_src : Option < OwnerId > ,
71
-
72
- // When a macro is disallowed in an early pass, it's stored
73
- // and emitted during the late pass. This happens for attributes.
74
- early_macro_cache : AttrStorage ,
75
71
}
76
72
77
73
impl DisallowedMacros {
78
- pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf , early_macro_cache : AttrStorage ) -> Self {
74
+ pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
79
75
let ( disallowed, _) = create_disallowed_map (
80
76
tcx,
81
77
& conf. disallowed_macros ,
@@ -88,7 +84,6 @@ impl DisallowedMacros {
88
84
disallowed,
89
85
seen : FxHashSet :: default ( ) ,
90
86
derive_src : None ,
91
- early_macro_cache,
92
87
}
93
88
}
94
89
@@ -125,15 +120,85 @@ impl DisallowedMacros {
125
120
}
126
121
127
122
impl_lint_pass ! ( DisallowedMacros => [ DISALLOWED_MACROS ] ) ;
128
-
129
123
impl LateLintPass < ' _ > for DisallowedMacros {
130
- fn check_crate ( & mut self , cx : & LateContext < ' _ > ) {
131
- // once we check a crate in the late pass we can emit the early pass lints
132
- if let Some ( attr_spans) = self . early_macro_cache . clone ( ) . 0 . get ( ) {
133
- for span in attr_spans {
134
- self . check ( cx, * span, None ) ;
135
- }
136
- }
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) => {
128
+ match kind {
129
+ AttributeKind :: Align { span, .. }
130
+ | AttributeKind :: AllowConstFnUnstable ( _, span)
131
+ | AttributeKind :: AllowIncoherentImpl ( span)
132
+ | AttributeKind :: AllowInternalUnstable ( _, span)
133
+ | AttributeKind :: AsPtr ( span)
134
+ | AttributeKind :: AutomaticallyDerived ( span)
135
+ | AttributeKind :: BodyStability { span, .. }
136
+ | AttributeKind :: Coinductive ( span)
137
+ | AttributeKind :: Cold ( span)
138
+ | AttributeKind :: Confusables { first_span : span, .. }
139
+ | AttributeKind :: ConstContinue ( span)
140
+ | AttributeKind :: ConstStability { span, .. }
141
+ | AttributeKind :: ConstTrait ( span)
142
+ | AttributeKind :: Coverage ( span, _)
143
+ | AttributeKind :: DenyExplicitImpl ( span)
144
+ | AttributeKind :: Deprecation { span, .. }
145
+ | AttributeKind :: DoNotImplementViaObject ( span)
146
+ | AttributeKind :: DocComment { span, .. }
147
+ | AttributeKind :: ExportName { span, .. }
148
+ | AttributeKind :: FfiConst ( span)
149
+ | AttributeKind :: FfiPure ( span)
150
+ | AttributeKind :: Ignore { span, .. }
151
+ | AttributeKind :: Inline ( _, span)
152
+ | AttributeKind :: LinkName { span, .. }
153
+ | AttributeKind :: LinkOrdinal { span, .. }
154
+ | AttributeKind :: LinkSection { span, .. }
155
+ | AttributeKind :: LoopMatch ( span)
156
+ | AttributeKind :: MacroEscape ( span)
157
+ | AttributeKind :: MacroUse { span, .. }
158
+ | AttributeKind :: Marker ( span)
159
+ | AttributeKind :: MayDangle ( span)
160
+ | AttributeKind :: MustUse { span, .. }
161
+ | AttributeKind :: Naked ( span)
162
+ | AttributeKind :: NoImplicitPrelude ( span)
163
+ | AttributeKind :: NoMangle ( span)
164
+ | AttributeKind :: NonExhaustive ( span)
165
+ | AttributeKind :: Optimize ( _, span)
166
+ | AttributeKind :: ParenSugar ( span)
167
+ | AttributeKind :: PassByValue ( span)
168
+ | AttributeKind :: Path ( _, span)
169
+ | AttributeKind :: Pointee ( span)
170
+ | AttributeKind :: ProcMacro ( span)
171
+ | AttributeKind :: ProcMacroAttribute ( span)
172
+ | AttributeKind :: ProcMacroDerive { span, .. }
173
+ | AttributeKind :: PubTransparent ( span)
174
+ | AttributeKind :: Repr { first_span : span, .. }
175
+ | AttributeKind :: RustcBuiltinMacro { span, .. }
176
+ | AttributeKind :: RustcLayoutScalarValidRangeEnd ( _, span)
177
+ | AttributeKind :: RustcLayoutScalarValidRangeStart ( _, span)
178
+ | AttributeKind :: SkipDuringMethodDispatch { span, .. }
179
+ | AttributeKind :: SpecializationTrait ( span)
180
+ | AttributeKind :: Stability { span, .. }
181
+ | AttributeKind :: StdInternalSymbol ( span)
182
+ | AttributeKind :: TargetFeature ( _, span)
183
+ | AttributeKind :: TrackCaller ( span)
184
+ | AttributeKind :: TypeConst ( span)
185
+ | AttributeKind :: UnsafeSpecializationMarker ( span)
186
+ | AttributeKind :: Used { span, .. } => * span,
187
+
188
+ AttributeKind :: CoherenceIsCore
189
+ | AttributeKind :: ConstStabilityIndirect
190
+ | AttributeKind :: Dummy
191
+ | AttributeKind :: ExportStable
192
+ | AttributeKind :: Fundamental
193
+ | AttributeKind :: MacroTransparency ( _)
194
+ | AttributeKind :: RustcObjectLifetimeDefault
195
+ | AttributeKind :: UnstableFeatureBound ( _) => {
196
+ return ;
197
+ } ,
198
+ }
199
+ } ,
200
+ } ;
201
+ self . check ( cx, span, self . derive_src ) ;
137
202
}
138
203
139
204
fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
0 commit comments