1717use crate :: { passes:: LateLintPassObject , LateContext , LateLintPass , LintStore } ;
1818use rustc_ast as ast;
1919use rustc_data_structures:: stack:: ensure_sufficient_stack;
20- use rustc_data_structures:: sync:: join;
20+ use rustc_data_structures:: sync:: { join, Lrc } ;
2121use rustc_hir as hir;
2222use rustc_hir:: def_id:: { LocalDefId , LocalModDefId } ;
2323use rustc_hir:: intravisit as hir_visit;
2424use rustc_middle:: hir:: nested_filter;
2525use rustc_middle:: ty:: { self , TyCtxt } ;
2626use rustc_session:: lint:: LintPass ;
27+ use rustc_session:: Session ;
2728use rustc_span:: Span ;
2829
2930use std:: any:: Any ;
3031use std:: cell:: Cell ;
3132
3233/// Extract the `LintStore` from the query context.
33- /// This function exists because we've erased `LintStore` as `dyn Any` in the context.
34- pub fn unerased_lint_store ( tcx : TyCtxt < ' _ > ) -> & LintStore {
35- let store: & dyn Any = & * tcx. lint_store ;
34+ /// This function exists because we've erased `LintStore` as `dyn Any` in the session.
35+ pub fn unerased_lint_store ( sess : & Session ) -> & LintStore {
36+ assert ! ( sess. lint_store. is_some( ) ) ;
37+ let store: & Lrc < _ > = sess. lint_store . as_ref ( ) . unwrap ( ) ;
38+ let store: & dyn Any = & * * store;
3639 store. downcast_ref ( ) . unwrap ( )
3740}
3841
@@ -353,7 +356,6 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
353356 cached_typeck_results : Cell :: new ( None ) ,
354357 param_env : ty:: ParamEnv :: empty ( ) ,
355358 effective_visibilities : & tcx. effective_visibilities ( ( ) ) ,
356- lint_store : unerased_lint_store ( tcx) ,
357359 last_node_with_lint_attrs : tcx. hir ( ) . local_def_id_to_hir_id ( module_def_id) ,
358360 generics : None ,
359361 only_module : true ,
@@ -362,8 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
362364 // Note: `passes` is often empty. In that case, it's faster to run
363365 // `builtin_lints` directly rather than bundling it up into the
364366 // `RuntimeCombinedLateLintPass`.
365- let mut passes: Vec < _ > =
366- unerased_lint_store ( tcx) . late_module_passes . iter ( ) . map ( |mk_pass| ( mk_pass) ( tcx) ) . collect ( ) ;
367+ let mut passes: Vec < _ > = unerased_lint_store ( & tcx. sess )
368+ . late_module_passes
369+ . iter ( )
370+ . map ( |mk_pass| ( mk_pass) ( tcx) )
371+ . collect ( ) ;
367372 if passes. is_empty ( ) {
368373 late_lint_mod_inner ( tcx, module_def_id, context, builtin_lints) ;
369374 } else {
@@ -400,7 +405,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
400405fn late_lint_crate < ' tcx > ( tcx : TyCtxt < ' tcx > ) {
401406 // Note: `passes` is often empty.
402407 let mut passes: Vec < _ > =
403- unerased_lint_store ( tcx) . late_passes . iter ( ) . map ( |mk_pass| ( mk_pass) ( tcx) ) . collect ( ) ;
408+ unerased_lint_store ( & tcx. sess ) . late_passes . iter ( ) . map ( |mk_pass| ( mk_pass) ( tcx) ) . collect ( ) ;
404409
405410 if passes. is_empty ( ) {
406411 return ;
@@ -412,7 +417,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
412417 cached_typeck_results : Cell :: new ( None ) ,
413418 param_env : ty:: ParamEnv :: empty ( ) ,
414419 effective_visibilities : & tcx. effective_visibilities ( ( ) ) ,
415- lint_store : unerased_lint_store ( tcx) ,
416420 last_node_with_lint_attrs : hir:: CRATE_HIR_ID ,
417421 generics : None ,
418422 only_module : false ,
0 commit comments