@@ -8,6 +8,7 @@ use rustc_ast::{self as ast, visit};
88use rustc_borrowck as mir_borrowck;
99use rustc_codegen_ssa:: traits:: CodegenBackend ;
1010use rustc_data_structures:: parallel;
11+ use rustc_data_structures:: steal:: Steal ;
1112use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
1213use rustc_errors:: PResult ;
1314use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
@@ -172,7 +173,7 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> {
172173/// harness if one is to be provided, injection of a dependency on the
173174/// standard library and prelude, and name resolution.
174175#[ instrument( level = "trace" , skip( tcx, krate, resolver) ) ]
175- pub fn configure_and_expand (
176+ fn configure_and_expand (
176177 tcx : TyCtxt < ' _ > ,
177178 mut krate : ast:: Crate ,
178179 resolver : & mut Resolver < ' _ , ' _ > ,
@@ -564,6 +565,34 @@ fn write_out_deps(
564565 }
565566}
566567
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+
567596fn output_filenames ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> Arc < OutputFilenames > {
568597 let sess = tcx. sess ;
569598 let _timer = sess. timer ( "prepare_outputs" ) ;
@@ -618,6 +647,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
618647 providers. analysis = analysis;
619648 providers. hir_crate = rustc_ast_lowering:: lower_to_hir;
620649 providers. output_filenames = output_filenames;
650+ providers. resolver_for_lowering = resolver_for_lowering;
621651 proc_macro_decls:: provide ( providers) ;
622652 rustc_const_eval:: provide ( providers) ;
623653 rustc_middle:: hir:: provide ( providers) ;
0 commit comments