17
17
use crate :: { passes:: LateLintPassObject , LateContext , LateLintPass , LintStore } ;
18
18
use rustc_ast as ast;
19
19
use rustc_data_structures:: stack:: ensure_sufficient_stack;
20
- use rustc_data_structures:: sync:: join;
20
+ use rustc_data_structures:: sync:: { join, Lrc } ;
21
21
use rustc_hir as hir;
22
22
use rustc_hir:: def_id:: { LocalDefId , LocalModDefId } ;
23
23
use rustc_hir:: intravisit as hir_visit;
24
24
use rustc_middle:: hir:: nested_filter;
25
25
use rustc_middle:: ty:: { self , TyCtxt } ;
26
26
use rustc_session:: lint:: LintPass ;
27
+ use rustc_session:: Session ;
27
28
use rustc_span:: Span ;
28
29
29
30
use std:: any:: Any ;
30
31
use std:: cell:: Cell ;
31
32
32
33
/// 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;
36
39
store. downcast_ref ( ) . unwrap ( )
37
40
}
38
41
@@ -353,7 +356,6 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
353
356
cached_typeck_results : Cell :: new ( None ) ,
354
357
param_env : ty:: ParamEnv :: empty ( ) ,
355
358
effective_visibilities : & tcx. effective_visibilities ( ( ) ) ,
356
- lint_store : unerased_lint_store ( tcx) ,
357
359
last_node_with_lint_attrs : tcx. hir ( ) . local_def_id_to_hir_id ( module_def_id) ,
358
360
generics : None ,
359
361
only_module : true ,
@@ -362,8 +364,11 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
362
364
// Note: `passes` is often empty. In that case, it's faster to run
363
365
// `builtin_lints` directly rather than bundling it up into the
364
366
// `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 ( ) ;
367
372
if passes. is_empty ( ) {
368
373
late_lint_mod_inner ( tcx, module_def_id, context, builtin_lints) ;
369
374
} else {
@@ -400,7 +405,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
400
405
fn late_lint_crate < ' tcx > ( tcx : TyCtxt < ' tcx > ) {
401
406
// Note: `passes` is often empty.
402
407
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 ( ) ;
404
409
405
410
if passes. is_empty ( ) {
406
411
return ;
@@ -412,7 +417,6 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
412
417
cached_typeck_results : Cell :: new ( None ) ,
413
418
param_env : ty:: ParamEnv :: empty ( ) ,
414
419
effective_visibilities : & tcx. effective_visibilities ( ( ) ) ,
415
- lint_store : unerased_lint_store ( tcx) ,
416
420
last_node_with_lint_attrs : hir:: CRATE_HIR_ID ,
417
421
generics : None ,
418
422
only_module : false ,
0 commit comments