@@ -28,7 +28,6 @@ use rustc_span::Span;
28
28
29
29
use std:: any:: Any ;
30
30
use std:: cell:: Cell ;
31
- use std:: slice;
32
31
33
32
/// Extract the `LintStore` from the query context.
34
33
/// This function exists because we've erased `LintStore` as `dyn Any` in the context.
@@ -313,45 +312,42 @@ impl LintPass for LateLintPassObjects<'_, '_> {
313
312
}
314
313
}
315
314
316
- macro_rules! expand_late_lint_pass_impl_methods {
317
- ( [ $hir: tt] , [ $( $( #[ $attr: meta] ) * fn $name: ident( $( $param: ident: $arg: ty) ,* ) ; ) * ] ) => (
318
- $( fn $name( & mut self , context: & LateContext <$hir>, $( $param: $arg) ,* ) {
319
- for obj in self . lints. iter_mut( ) {
320
- obj. $name( context, $( $param) ,* ) ;
321
- }
322
- } ) *
323
- )
324
- }
325
-
326
315
macro_rules! late_lint_pass_impl {
327
- ( [ ] , [ $hir: tt] , $methods : tt ) => {
316
+ ( [ ] , [ $hir: tt] , [ $ ( $ ( # [ $attr : meta ] ) * fn $name : ident ( $ ( $param : ident : $arg : ty ) , * ) ; ) * ] ) => {
328
317
impl <$hir> LateLintPass <$hir> for LateLintPassObjects <' _, $hir> {
329
- expand_late_lint_pass_impl_methods!( [ $hir] , $methods) ;
318
+ $( fn $name( & mut self , context: & LateContext <$hir>, $( $param: $arg) ,* ) {
319
+ for obj in self . lints. iter_mut( ) {
320
+ obj. $name( context, $( $param) ,* ) ;
321
+ }
322
+ } ) *
330
323
}
331
324
} ;
332
325
}
333
326
334
327
crate :: late_lint_methods!( late_lint_pass_impl, [ ] , [ ' tcx] ) ;
335
328
336
- fn late_lint_mod_pass < ' tcx , T : LateLintPass < ' tcx > > (
329
+ pub ( super ) fn late_lint_mod < ' tcx , T : LateLintPass < ' tcx > + ' tcx > (
337
330
tcx : TyCtxt < ' tcx > ,
338
331
module_def_id : LocalDefId ,
339
- pass : T ,
332
+ builtin_lints : T ,
340
333
) {
341
- let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
342
-
343
334
let context = LateContext {
344
335
tcx,
345
336
enclosing_body : None ,
346
337
cached_typeck_results : Cell :: new ( None ) ,
347
338
param_env : ty:: ParamEnv :: empty ( ) ,
348
- effective_visibilities,
339
+ effective_visibilities : & tcx . effective_visibilities ( ( ) ) ,
349
340
lint_store : unerased_lint_store ( tcx) ,
350
341
last_node_with_lint_attrs : tcx. hir ( ) . local_def_id_to_hir_id ( module_def_id) ,
351
342
generics : None ,
352
343
only_module : true ,
353
344
} ;
354
345
346
+ let mut passes: Vec < _ > =
347
+ unerased_lint_store ( tcx) . late_module_passes . iter ( ) . map ( |pass| ( pass) ( tcx) ) . collect ( ) ;
348
+ passes. push ( Box :: new ( builtin_lints) ) ;
349
+ let pass = LateLintPassObjects { lints : & mut passes[ ..] } ;
350
+
355
351
let mut cx = LateContextAndPass { context, pass } ;
356
352
357
353
let ( module, _span, hir_id) = tcx. hir ( ) . get_module ( module_def_id) ;
@@ -365,46 +361,29 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
365
361
}
366
362
}
367
363
368
- pub fn late_lint_mod < ' tcx , T : LateLintPass < ' tcx > > (
369
- tcx : TyCtxt < ' tcx > ,
370
- module_def_id : LocalDefId ,
371
- builtin_lints : T ,
372
- ) {
373
- if tcx. sess . opts . unstable_opts . no_interleave_lints {
374
- // These passes runs in late_lint_crate with -Z no_interleave_lints
375
- return ;
376
- }
377
-
378
- late_lint_mod_pass ( tcx, module_def_id, builtin_lints) ;
379
-
380
- let mut passes: Vec < _ > =
381
- unerased_lint_store ( tcx) . late_module_passes . iter ( ) . map ( |pass| ( pass) ( tcx) ) . collect ( ) ;
382
-
383
- if !passes. is_empty ( ) {
384
- late_lint_mod_pass ( tcx, module_def_id, LateLintPassObjects { lints : & mut passes[ ..] } ) ;
385
- }
386
- }
387
-
388
- fn late_lint_pass_crate < ' tcx , T : LateLintPass < ' tcx > > ( tcx : TyCtxt < ' tcx > , pass : T ) {
389
- let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
390
-
364
+ fn late_lint_crate < ' tcx , T : LateLintPass < ' tcx > + ' tcx > ( tcx : TyCtxt < ' tcx > , builtin_lints : T ) {
391
365
let context = LateContext {
392
366
tcx,
393
367
enclosing_body : None ,
394
368
cached_typeck_results : Cell :: new ( None ) ,
395
369
param_env : ty:: ParamEnv :: empty ( ) ,
396
- effective_visibilities,
370
+ effective_visibilities : & tcx . effective_visibilities ( ( ) ) ,
397
371
lint_store : unerased_lint_store ( tcx) ,
398
372
last_node_with_lint_attrs : hir:: CRATE_HIR_ID ,
399
373
generics : None ,
400
374
only_module : false ,
401
375
} ;
402
376
377
+ let mut passes =
378
+ unerased_lint_store ( tcx) . late_passes . iter ( ) . map ( |p| ( p) ( tcx) ) . collect :: < Vec < _ > > ( ) ;
379
+ passes. push ( Box :: new ( builtin_lints) ) ;
380
+ let pass = LateLintPassObjects { lints : & mut passes[ ..] } ;
381
+
403
382
let mut cx = LateContextAndPass { context, pass } ;
404
383
405
384
// Visit the whole crate.
406
385
cx. with_lint_attrs ( hir:: CRATE_HIR_ID , |cx| {
407
- // since the root module isn't visited as an item (because it isn't an
386
+ // Since the root module isn't visited as an item (because it isn't an
408
387
// item), warn for it here.
409
388
lint_callback ! ( cx, check_crate, ) ;
410
389
tcx. hir ( ) . walk_toplevel_module ( cx) ;
@@ -413,41 +392,8 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
413
392
} )
414
393
}
415
394
416
- fn late_lint_crate < ' tcx , T : LateLintPass < ' tcx > > ( tcx : TyCtxt < ' tcx > , builtin_lints : T ) {
417
- let mut passes =
418
- unerased_lint_store ( tcx) . late_passes . iter ( ) . map ( |p| ( p) ( tcx) ) . collect :: < Vec < _ > > ( ) ;
419
-
420
- if !tcx. sess . opts . unstable_opts . no_interleave_lints {
421
- if !passes. is_empty ( ) {
422
- late_lint_pass_crate ( tcx, LateLintPassObjects { lints : & mut passes[ ..] } ) ;
423
- }
424
-
425
- late_lint_pass_crate ( tcx, builtin_lints) ;
426
- } else {
427
- for pass in & mut passes {
428
- tcx. sess . prof . verbose_generic_activity_with_arg ( "run_late_lint" , pass. name ( ) ) . run (
429
- || {
430
- late_lint_pass_crate ( tcx, LateLintPassObjects { lints : slice:: from_mut ( pass) } ) ;
431
- } ,
432
- ) ;
433
- }
434
-
435
- let mut passes: Vec < _ > =
436
- unerased_lint_store ( tcx) . late_module_passes . iter ( ) . map ( |pass| ( pass) ( tcx) ) . collect ( ) ;
437
-
438
- for pass in & mut passes {
439
- tcx. sess
440
- . prof
441
- . verbose_generic_activity_with_arg ( "run_late_module_lint" , pass. name ( ) )
442
- . run ( || {
443
- late_lint_pass_crate ( tcx, LateLintPassObjects { lints : slice:: from_mut ( pass) } ) ;
444
- } ) ;
445
- }
446
- }
447
- }
448
-
449
395
/// Performs lint checking on a crate.
450
- pub fn check_crate < ' tcx , T : LateLintPass < ' tcx > > (
396
+ pub fn check_crate < ' tcx , T : LateLintPass < ' tcx > + ' tcx > (
451
397
tcx : TyCtxt < ' tcx > ,
452
398
builtin_lints : impl FnOnce ( ) -> T + Send ,
453
399
) {
0 commit comments