@@ -28,7 +28,6 @@ use rustc_span::Span;
2828
2929use std:: any:: Any ;
3030use std:: cell:: Cell ;
31- use std:: slice;
3231
3332/// Extract the `LintStore` from the query context.
3433/// This function exists because we've erased `LintStore` as `dyn Any` in the context.
@@ -313,45 +312,42 @@ impl LintPass for LateLintPassObjects<'_, '_> {
313312 }
314313}
315314
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-
326315macro_rules! late_lint_pass_impl {
327- ( [ ] , [ $hir: tt] , $methods : tt ) => {
316+ ( [ ] , [ $hir: tt] , [ $ ( $ ( # [ $attr : meta ] ) * fn $name : ident ( $ ( $param : ident : $arg : ty ) , * ) ; ) * ] ) => {
328317 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+ } ) *
330323 }
331324 } ;
332325}
333326
334327crate :: late_lint_methods!( late_lint_pass_impl, [ ] , [ ' tcx] ) ;
335328
336- fn late_lint_mod_pass < ' tcx , T : LateLintPass < ' tcx > > (
329+ pub ( super ) fn late_lint_mod < ' tcx , T : LateLintPass < ' tcx > + ' tcx > (
337330 tcx : TyCtxt < ' tcx > ,
338331 module_def_id : LocalDefId ,
339- pass : T ,
332+ builtin_lints : T ,
340333) {
341- let effective_visibilities = & tcx. effective_visibilities ( ( ) ) ;
342-
343334 let context = LateContext {
344335 tcx,
345336 enclosing_body : None ,
346337 cached_typeck_results : Cell :: new ( None ) ,
347338 param_env : ty:: ParamEnv :: empty ( ) ,
348- effective_visibilities,
339+ effective_visibilities : & tcx . effective_visibilities ( ( ) ) ,
349340 lint_store : unerased_lint_store ( tcx) ,
350341 last_node_with_lint_attrs : tcx. hir ( ) . local_def_id_to_hir_id ( module_def_id) ,
351342 generics : None ,
352343 only_module : true ,
353344 } ;
354345
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+
355351 let mut cx = LateContextAndPass { context, pass } ;
356352
357353 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>>(
365361 }
366362}
367363
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 ) {
391365 let context = LateContext {
392366 tcx,
393367 enclosing_body : None ,
394368 cached_typeck_results : Cell :: new ( None ) ,
395369 param_env : ty:: ParamEnv :: empty ( ) ,
396- effective_visibilities,
370+ effective_visibilities : & tcx . effective_visibilities ( ( ) ) ,
397371 lint_store : unerased_lint_store ( tcx) ,
398372 last_node_with_lint_attrs : hir:: CRATE_HIR_ID ,
399373 generics : None ,
400374 only_module : false ,
401375 } ;
402376
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+
403382 let mut cx = LateContextAndPass { context, pass } ;
404383
405384 // Visit the whole crate.
406385 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
408387 // item), warn for it here.
409388 lint_callback ! ( cx, check_crate, ) ;
410389 tcx. hir ( ) . walk_toplevel_module ( cx) ;
@@ -413,41 +392,8 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
413392 } )
414393}
415394
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-
449395/// 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 > (
451397 tcx : TyCtxt < ' tcx > ,
452398 builtin_lints : impl FnOnce ( ) -> T + Send ,
453399) {
0 commit comments