@@ -15,8 +15,9 @@ use rustc_hir::definitions::Definitions;
15
15
use rustc_index:: IndexVec ;
16
16
use rustc_middle:: ty:: TyCtxt ;
17
17
use 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
+ } ;
20
21
use rustc_session:: lint;
21
22
use rustc_session:: output:: validate_crate_name;
22
23
use rustc_session:: search_paths:: PathKind ;
@@ -33,6 +34,8 @@ use std::time::Duration;
33
34
use std:: { cmp, env, iter} ;
34
35
35
36
pub struct CStore {
37
+ metadata_loader : Box < MetadataLoaderDyn > ,
38
+
36
39
metas : IndexVec < CrateNum , Option < Box < CrateMetadata > > > ,
37
40
injected_panic_runtime : Option < CrateNum > ,
38
41
/// This crate needs an allocator and either provides it itself, or finds it in a dependency.
@@ -261,10 +264,14 @@ impl CStore {
261
264
}
262
265
}
263
266
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 {
265
271
let mut stable_crate_ids = StableCrateIdMap :: default ( ) ;
266
272
stable_crate_ids. insert ( local_stable_crate_id, LOCAL_CRATE ) ;
267
273
CStore {
274
+ metadata_loader,
268
275
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
269
276
// order to make array indices in `metas` match with the
270
277
// corresponding `CrateNum`. This first entry will always remain
@@ -538,10 +545,9 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
538
545
( LoadResult :: Previous ( cnum) , None )
539
546
} else {
540
547
info ! ( "falling back to a load" ) ;
541
- let metadata_loader = self . tcx . metadata_loader ( ( ) ) . borrow ( ) ;
542
548
let mut locator = CrateLocator :: new (
543
549
self . sess ,
544
- & * * metadata_loader,
550
+ & * self . cstore . metadata_loader ,
545
551
name,
546
552
// The all loop is because `--crate-type=rlib --crate-type=rlib` is
547
553
// legal and produces both inside this type.
0 commit comments