@@ -20,21 +20,23 @@ use rustc_ast::ptr::P;
20
20
use rustc_ast:: visit:: { self as ast_visit, Visitor } ;
21
21
use rustc_ast:: { self as ast, walk_list, HasAttrs } ;
22
22
use rustc_middle:: ty:: RegisteredTools ;
23
- use rustc_session:: lint:: { BufferedEarlyLint , LintBuffer , LintPass } ;
23
+ use rustc_session:: lint:: { BufferedEarlyLint , LintBuffer } ;
24
24
use rustc_session:: Session ;
25
25
use rustc_span:: symbol:: Ident ;
26
26
use rustc_span:: Span ;
27
27
28
- macro_rules! run_early_pass { ( $cx: expr, $f: ident, $( $args: expr) ,* ) => ( {
29
- $cx. pass. $f( & $cx. context, $( $args) ,* ) ;
28
+ macro_rules! run_early_passes { ( $cx: expr, $f: ident, $( $args: expr) ,* ) => ( {
29
+ for pass in $cx. passes. iter_mut( ) {
30
+ pass. $f( & $cx. context, $( $args) ,* ) ;
31
+ }
30
32
} ) }
31
33
32
- pub struct EarlyContextAndPass < ' a , T : EarlyLintPass > {
34
+ pub struct EarlyContextAndPasses < ' a > {
33
35
context : EarlyContext < ' a > ,
34
- pass : T ,
36
+ passes : Vec < EarlyLintPassObject > ,
35
37
}
36
38
37
- impl < ' a , T : EarlyLintPass > EarlyContextAndPass < ' a , T > {
39
+ impl < ' a > EarlyContextAndPasses < ' a > {
38
40
fn check_id ( & mut self , id : ast:: NodeId ) {
39
41
for early_lint in self . context . buffered . take ( id) {
40
42
let BufferedEarlyLint { span, msg, node_id : _, lint_id, diagnostic } = early_lint;
@@ -61,27 +63,27 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
61
63
62
64
self . check_id ( id) ;
63
65
debug ! ( "early context: enter_attrs({:?})" , attrs) ;
64
- run_early_pass ! ( self , enter_lint_attrs, attrs) ;
66
+ run_early_passes ! ( self , enter_lint_attrs, attrs) ;
65
67
f ( self ) ;
66
68
debug ! ( "early context: exit_attrs({:?})" , attrs) ;
67
- run_early_pass ! ( self , exit_lint_attrs, attrs) ;
69
+ run_early_passes ! ( self , exit_lint_attrs, attrs) ;
68
70
self . context . builder . pop ( push) ;
69
71
}
70
72
}
71
73
72
- impl < ' a , T : EarlyLintPass > ast_visit:: Visitor < ' a > for EarlyContextAndPass < ' a , T > {
74
+ impl < ' a > ast_visit:: Visitor < ' a > for EarlyContextAndPasses < ' a > {
73
75
fn visit_param ( & mut self , param : & ' a ast:: Param ) {
74
76
self . with_lint_attrs ( param. id , & param. attrs , |cx| {
75
- run_early_pass ! ( cx, check_param, param) ;
77
+ run_early_passes ! ( cx, check_param, param) ;
76
78
ast_visit:: walk_param ( cx, param) ;
77
79
} ) ;
78
80
}
79
81
80
82
fn visit_item ( & mut self , it : & ' a ast:: Item ) {
81
83
self . with_lint_attrs ( it. id , & it. attrs , |cx| {
82
- run_early_pass ! ( cx, check_item, it) ;
84
+ run_early_passes ! ( cx, check_item, it) ;
83
85
ast_visit:: walk_item ( cx, it) ;
84
- run_early_pass ! ( cx, check_item_post, it) ;
86
+ run_early_passes ! ( cx, check_item_post, it) ;
85
87
} )
86
88
}
87
89
@@ -92,10 +94,10 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
92
94
}
93
95
94
96
fn visit_pat ( & mut self , p : & ' a ast:: Pat ) {
95
- run_early_pass ! ( self , check_pat, p) ;
97
+ run_early_passes ! ( self , check_pat, p) ;
96
98
self . check_id ( p. id ) ;
97
99
ast_visit:: walk_pat ( self , p) ;
98
- run_early_pass ! ( self , check_pat_post, p) ;
100
+ run_early_passes ! ( self , check_pat_post, p) ;
99
101
}
100
102
101
103
fn visit_pat_field ( & mut self , field : & ' a ast:: PatField ) {
@@ -111,7 +113,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
111
113
112
114
fn visit_expr ( & mut self , e : & ' a ast:: Expr ) {
113
115
self . with_lint_attrs ( e. id , & e. attrs , |cx| {
114
- run_early_pass ! ( cx, check_expr, e) ;
116
+ run_early_passes ! ( cx, check_expr, e) ;
115
117
ast_visit:: walk_expr ( cx, e) ;
116
118
} )
117
119
}
@@ -132,7 +134,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
132
134
// Note that statements get their attributes from
133
135
// the AST struct that they wrap (e.g. an item)
134
136
self . with_lint_attrs ( s. id , s. attrs ( ) , |cx| {
135
- run_early_pass ! ( cx, check_stmt, s) ;
137
+ run_early_passes ! ( cx, check_stmt, s) ;
136
138
cx. check_id ( s. id ) ;
137
139
} ) ;
138
140
// The visitor for the AST struct wrapped
@@ -143,7 +145,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
143
145
}
144
146
145
147
fn visit_fn ( & mut self , fk : ast_visit:: FnKind < ' a > , span : Span , id : ast:: NodeId ) {
146
- run_early_pass ! ( self , check_fn, fk, span, id) ;
148
+ run_early_passes ! ( self , check_fn, fk, span, id) ;
147
149
self . check_id ( id) ;
148
150
ast_visit:: walk_fn ( self , fk) ;
149
151
@@ -171,37 +173,37 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
171
173
172
174
fn visit_variant ( & mut self , v : & ' a ast:: Variant ) {
173
175
self . with_lint_attrs ( v. id , & v. attrs , |cx| {
174
- run_early_pass ! ( cx, check_variant, v) ;
176
+ run_early_passes ! ( cx, check_variant, v) ;
175
177
ast_visit:: walk_variant ( cx, v) ;
176
178
} )
177
179
}
178
180
179
181
fn visit_ty ( & mut self , t : & ' a ast:: Ty ) {
180
- run_early_pass ! ( self , check_ty, t) ;
182
+ run_early_passes ! ( self , check_ty, t) ;
181
183
self . check_id ( t. id ) ;
182
184
ast_visit:: walk_ty ( self , t) ;
183
185
}
184
186
185
187
fn visit_ident ( & mut self , ident : Ident ) {
186
- run_early_pass ! ( self , check_ident, ident) ;
188
+ run_early_passes ! ( self , check_ident, ident) ;
187
189
}
188
190
189
191
fn visit_local ( & mut self , l : & ' a ast:: Local ) {
190
192
self . with_lint_attrs ( l. id , & l. attrs , |cx| {
191
- run_early_pass ! ( cx, check_local, l) ;
193
+ run_early_passes ! ( cx, check_local, l) ;
192
194
ast_visit:: walk_local ( cx, l) ;
193
195
} )
194
196
}
195
197
196
198
fn visit_block ( & mut self , b : & ' a ast:: Block ) {
197
- run_early_pass ! ( self , check_block, b) ;
199
+ run_early_passes ! ( self , check_block, b) ;
198
200
self . check_id ( b. id ) ;
199
201
ast_visit:: walk_block ( self , b) ;
200
202
}
201
203
202
204
fn visit_arm ( & mut self , a : & ' a ast:: Arm ) {
203
205
self . with_lint_attrs ( a. id , & a. attrs , |cx| {
204
- run_early_pass ! ( cx, check_arm, a) ;
206
+ run_early_passes ! ( cx, check_arm, a) ;
205
207
ast_visit:: walk_arm ( cx, a) ;
206
208
} )
207
209
}
@@ -220,19 +222,19 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
220
222
}
221
223
222
224
fn visit_generic_arg ( & mut self , arg : & ' a ast:: GenericArg ) {
223
- run_early_pass ! ( self , check_generic_arg, arg) ;
225
+ run_early_passes ! ( self , check_generic_arg, arg) ;
224
226
ast_visit:: walk_generic_arg ( self , arg) ;
225
227
}
226
228
227
229
fn visit_generic_param ( & mut self , param : & ' a ast:: GenericParam ) {
228
230
self . with_lint_attrs ( param. id , & param. attrs , |cx| {
229
- run_early_pass ! ( cx, check_generic_param, param) ;
231
+ run_early_passes ! ( cx, check_generic_param, param) ;
230
232
ast_visit:: walk_generic_param ( cx, param) ;
231
233
} ) ;
232
234
}
233
235
234
236
fn visit_generics ( & mut self , g : & ' a ast:: Generics ) {
235
- run_early_pass ! ( self , check_generics, g) ;
237
+ run_early_passes ! ( self , check_generics, g) ;
236
238
ast_visit:: walk_generics ( self , g) ;
237
239
}
238
240
@@ -241,18 +243,18 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
241
243
}
242
244
243
245
fn visit_poly_trait_ref ( & mut self , t : & ' a ast:: PolyTraitRef ) {
244
- run_early_pass ! ( self , check_poly_trait_ref, t) ;
246
+ run_early_passes ! ( self , check_poly_trait_ref, t) ;
245
247
ast_visit:: walk_poly_trait_ref ( self , t) ;
246
248
}
247
249
248
250
fn visit_assoc_item ( & mut self , item : & ' a ast:: AssocItem , ctxt : ast_visit:: AssocCtxt ) {
249
251
self . with_lint_attrs ( item. id , & item. attrs , |cx| match ctxt {
250
252
ast_visit:: AssocCtxt :: Trait => {
251
- run_early_pass ! ( cx, check_trait_item, item) ;
253
+ run_early_passes ! ( cx, check_trait_item, item) ;
252
254
ast_visit:: walk_assoc_item ( cx, item, ctxt) ;
253
255
}
254
256
ast_visit:: AssocCtxt :: Impl => {
255
- run_early_pass ! ( cx, check_impl_item, item) ;
257
+ run_early_passes ! ( cx, check_impl_item, item) ;
256
258
ast_visit:: walk_assoc_item ( cx, item, ctxt) ;
257
259
}
258
260
} ) ;
@@ -273,53 +275,28 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
273
275
}
274
276
275
277
fn visit_attribute ( & mut self , attr : & ' a ast:: Attribute ) {
276
- run_early_pass ! ( self , check_attribute, attr) ;
278
+ run_early_passes ! ( self , check_attribute, attr) ;
277
279
}
278
280
279
281
fn visit_mac_def ( & mut self , mac : & ' a ast:: MacroDef , id : ast:: NodeId ) {
280
- run_early_pass ! ( self , check_mac_def, mac) ;
282
+ run_early_passes ! ( self , check_mac_def, mac) ;
281
283
self . check_id ( id) ;
282
284
}
283
285
284
286
fn visit_mac_call ( & mut self , mac : & ' a ast:: MacCall ) {
285
- run_early_pass ! ( self , check_mac, mac) ;
287
+ run_early_passes ! ( self , check_mac, mac) ;
286
288
ast_visit:: walk_mac ( self , mac) ;
287
289
}
288
290
}
289
291
290
- struct EarlyLintPassObjects < ' a > {
291
- lints : & ' a mut [ EarlyLintPassObject ] ,
292
- }
293
-
294
- #[ allow( rustc:: lint_pass_impl_without_macro) ]
295
- impl LintPass for EarlyLintPassObjects < ' _ > {
296
- fn name ( & self ) -> & ' static str {
297
- panic ! ( )
298
- }
299
- }
300
-
301
- macro_rules! early_lint_pass_impl {
302
- ( [ ] , [ $( $( #[ $attr: meta] ) * fn $name: ident( $( $param: ident: $arg: ty) ,* ) ; ) * ] ) => (
303
- impl EarlyLintPass for EarlyLintPassObjects <' _> {
304
- $( fn $name( & mut self , context: & EarlyContext <' _>, $( $param: $arg) ,* ) {
305
- for obj in self . lints. iter_mut( ) {
306
- obj. $name( context, $( $param) ,* ) ;
307
- }
308
- } ) *
309
- }
310
- )
311
- }
312
-
313
- crate :: early_lint_methods!( early_lint_pass_impl, [ ] ) ;
314
-
315
292
/// Early lints work on different nodes - either on the crate root, or on freshly loaded modules.
316
293
/// This trait generalizes over those nodes.
317
294
pub trait EarlyCheckNode < ' a > : Copy {
318
295
fn id ( self ) -> ast:: NodeId ;
319
296
fn attrs < ' b > ( self ) -> & ' b [ ast:: Attribute ]
320
297
where
321
298
' a : ' b ;
322
- fn check < ' b > ( self , cx : & mut EarlyContextAndPass < ' b , impl EarlyLintPass > )
299
+ fn check < ' b > ( self , cx : & mut EarlyContextAndPasses < ' b > )
323
300
where
324
301
' a : ' b ;
325
302
}
@@ -334,13 +311,13 @@ impl<'a> EarlyCheckNode<'a> for &'a ast::Crate {
334
311
{
335
312
& self . attrs
336
313
}
337
- fn check < ' b > ( self , cx : & mut EarlyContextAndPass < ' b , impl EarlyLintPass > )
314
+ fn check < ' b > ( self , cx : & mut EarlyContextAndPasses < ' b > )
338
315
where
339
316
' a : ' b ,
340
317
{
341
- run_early_pass ! ( cx, check_crate, self ) ;
318
+ run_early_passes ! ( cx, check_crate, self ) ;
342
319
ast_visit:: walk_crate ( cx, self ) ;
343
- run_early_pass ! ( cx, check_crate_post, self ) ;
320
+ run_early_passes ! ( cx, check_crate_post, self ) ;
344
321
}
345
322
}
346
323
@@ -354,7 +331,7 @@ impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [P<ast::
354
331
{
355
332
self . 1
356
333
}
357
- fn check < ' b > ( self , cx : & mut EarlyContextAndPass < ' b , impl EarlyLintPass > )
334
+ fn check < ' b > ( self , cx : & mut EarlyContextAndPasses < ' b > )
358
335
where
359
336
' a : ' b ,
360
337
{
@@ -374,18 +351,18 @@ pub fn check_ast_node<'a>(
374
351
) {
375
352
let passes =
376
353
if pre_expansion { & lint_store. pre_expansion_passes } else { & lint_store. early_passes } ;
377
- let mut passes: Vec < _ > = passes. iter ( ) . map ( |p| ( p) ( ) ) . collect ( ) ;
354
+ let mut passes: Vec < EarlyLintPassObject > = passes. iter ( ) . map ( |p| ( p) ( ) ) . collect ( ) ;
378
355
passes. push ( Box :: new ( builtin_lints) ) ;
379
356
380
- let mut cx = EarlyContextAndPass {
357
+ let mut cx = EarlyContextAndPasses {
381
358
context : EarlyContext :: new (
382
359
sess,
383
360
!pre_expansion,
384
361
lint_store,
385
362
registered_tools,
386
363
lint_buffer. unwrap_or_default ( ) ,
387
364
) ,
388
- pass : EarlyLintPassObjects { lints : & mut passes[ .. ] } ,
365
+ passes,
389
366
} ;
390
367
cx. with_lint_attrs ( check_node. id ( ) , check_node. attrs ( ) , |cx| check_node. check ( cx) ) ;
391
368
0 commit comments