@@ -15,8 +15,9 @@ use rustc_hir::definitions::Definitions;
1515use rustc_index:: IndexVec ;
1616use rustc_middle:: ty:: TyCtxt ;
1717use rustc_session:: config:: { self , CrateType , ExternLocation } ;
18- use rustc_session:: cstore:: ExternCrateSource ;
19- use rustc_session:: cstore:: { CrateDepKind , CrateSource , ExternCrate } ;
18+ use rustc_session:: cstore:: {
19+ CrateDepKind , CrateSource , ExternCrate , ExternCrateSource , MetadataLoaderDyn ,
20+ } ;
2021use rustc_session:: lint;
2122use rustc_session:: output:: validate_crate_name;
2223use rustc_session:: search_paths:: PathKind ;
@@ -33,6 +34,8 @@ use std::time::Duration;
3334use std:: { cmp, env, iter} ;
3435
3536pub struct CStore {
37+ metadata_loader : Box < MetadataLoaderDyn > ,
38+
3639 metas : IndexVec < CrateNum , Option < Box < CrateMetadata > > > ,
3740 injected_panic_runtime : Option < CrateNum > ,
3841 /// This crate needs an allocator and either provides it itself, or finds it in a dependency.
@@ -261,10 +264,14 @@ impl CStore {
261264 }
262265 }
263266
264- pub fn new ( local_stable_crate_id : StableCrateId ) -> CStore {
267+ pub fn new (
268+ metadata_loader : Box < MetadataLoaderDyn > ,
269+ local_stable_crate_id : StableCrateId ,
270+ ) -> CStore {
265271 let mut stable_crate_ids = StableCrateIdMap :: default ( ) ;
266272 stable_crate_ids. insert ( local_stable_crate_id, LOCAL_CRATE ) ;
267273 CStore {
274+ metadata_loader,
268275 // We add an empty entry for LOCAL_CRATE (which maps to zero) in
269276 // order to make array indices in `metas` match with the
270277 // corresponding `CrateNum`. This first entry will always remain
@@ -538,10 +545,9 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
538545 ( LoadResult :: Previous ( cnum) , None )
539546 } else {
540547 info ! ( "falling back to a load" ) ;
541- let metadata_loader = self . tcx . metadata_loader ( ( ) ) . borrow ( ) ;
542548 let mut locator = CrateLocator :: new (
543549 self . sess ,
544- & * * metadata_loader,
550+ & * self . cstore . metadata_loader ,
545551 name,
546552 // The all loop is because `--crate-type=rlib --crate-type=rlib` is
547553 // legal and produces both inside this type.
0 commit comments