@@ -8,6 +8,7 @@ use rustc_ast::{self as ast, visit};
8
8
use rustc_borrowck as mir_borrowck;
9
9
use rustc_codegen_ssa:: traits:: CodegenBackend ;
10
10
use rustc_data_structures:: parallel;
11
+ use rustc_data_structures:: steal:: Steal ;
11
12
use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
12
13
use rustc_errors:: PResult ;
13
14
use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
@@ -172,7 +173,7 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
172
173
/// harness if one is to be provided, injection of a dependency on the
173
174
/// standard library and prelude, and name resolution.
174
175
#[ instrument( level = "trace" , skip( tcx, krate, resolver) ) ]
175
- pub fn configure_and_expand (
176
+ fn configure_and_expand (
176
177
tcx : TyCtxt < ' _ > ,
177
178
mut krate : ast:: Crate ,
178
179
resolver : & mut Resolver < ' _ , ' _ > ,
@@ -564,6 +565,34 @@ fn write_out_deps(
564
565
}
565
566
}
566
567
568
+ fn resolver_for_lowering < ' tcx > (
569
+ tcx : TyCtxt < ' tcx > ,
570
+ ( ) : ( ) ,
571
+ ) -> & ' tcx Steal < ( ty:: ResolverAstLowering , Lrc < ast:: Crate > ) > {
572
+ let arenas = Resolver :: arenas ( ) ;
573
+ let krate = tcx. crate_for_resolver ( ( ) ) . steal ( ) ;
574
+ let mut resolver = Resolver :: new (
575
+ tcx,
576
+ & krate,
577
+ tcx. crate_name ( LOCAL_CRATE ) ,
578
+ tcx. metadata_loader ( ( ) ) . steal ( ) ,
579
+ & arenas,
580
+ ) ;
581
+ let krate = configure_and_expand ( tcx, krate, & mut resolver) ;
582
+
583
+ // Make sure we don't mutate the cstore from here on.
584
+ tcx. untracked ( ) . cstore . leak ( ) ;
585
+
586
+ let ty:: ResolverOutputs {
587
+ global_ctxt : untracked_resolutions,
588
+ ast_lowering : untracked_resolver_for_lowering,
589
+ } = resolver. into_outputs ( ) ;
590
+
591
+ let feed = tcx. feed_unit_query ( ) ;
592
+ feed. resolutions ( tcx. arena . alloc ( untracked_resolutions) ) ;
593
+ tcx. arena . alloc ( Steal :: new ( ( untracked_resolver_for_lowering, Lrc :: new ( krate) ) ) )
594
+ }
595
+
567
596
fn output_filenames ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Arc < OutputFilenames > {
568
597
let sess = tcx. sess ;
569
598
let _timer = sess. timer ( "prepare_outputs" ) ;
@@ -618,6 +647,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
618
647
providers. analysis = analysis;
619
648
providers. hir_crate = rustc_ast_lowering:: lower_to_hir;
620
649
providers. output_filenames = output_filenames;
650
+ providers. resolver_for_lowering = resolver_for_lowering;
621
651
proc_macro_decls:: provide ( providers) ;
622
652
rustc_const_eval:: provide ( providers) ;
623
653
rustc_middle:: hir:: provide ( providers) ;
0 commit comments