@@ -12,6 +12,7 @@ use rustc_data_structures::fx::FxHashSet;
12
12
use rustc_data_structures:: owned_slice:: OwnedSlice ;
13
13
use rustc_data_structures:: svh:: Svh ;
14
14
use rustc_data_structures:: sync:: { self , FreezeReadGuard , FreezeWriteGuard } ;
15
+ use rustc_data_structures:: unord:: UnordMap ;
15
16
use rustc_errors:: DiagCtxtHandle ;
16
17
use rustc_expand:: base:: SyntaxExtension ;
17
18
use rustc_fs_util:: try_canonicalize;
@@ -68,6 +69,9 @@ pub struct CStore {
68
69
/// This crate has a `#[alloc_error_handler]` item.
69
70
has_alloc_error_handler : bool ,
70
71
72
+ /// Names that were used to load the crates via `extern crate` or paths.
73
+ resolved_externs : UnordMap < Symbol , CrateNum > ,
74
+
71
75
/// Unused externs of the crate
72
76
unused_externs : Vec < Symbol > ,
73
77
}
@@ -268,6 +272,14 @@ impl CStore {
268
272
self . metas [ cnum] = Some ( Box :: new ( data) ) ;
269
273
}
270
274
275
+ /// Save the name used to resolve the extern crate in the local crate
276
+ ///
277
+ /// The name isn't always the crate's own name, because `sess.opts.externs` can assign it another name.
278
+ /// It's also not always the same as the `DefId`'s symbol due to renames `extern crate name as defid_name`.
279
+ pub ( crate ) fn set_resolved_extern_crate_name ( & mut self , name : Symbol , extern_crate : CrateNum ) {
280
+ self . resolved_externs . insert ( name, extern_crate) ;
281
+ }
282
+
271
283
pub ( crate ) fn iter_crate_data ( & self ) -> impl Iterator < Item = ( CrateNum , & CrateMetadata ) > {
272
284
self . metas
273
285
. iter_enumerated ( )
@@ -494,6 +506,7 @@ impl CStore {
494
506
alloc_error_handler_kind : None ,
495
507
has_global_allocator : false ,
496
508
has_alloc_error_handler : false ,
509
+ resolved_externs : UnordMap :: default ( ) ,
497
510
unused_externs : Vec :: new ( ) ,
498
511
}
499
512
}
@@ -1302,6 +1315,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1302
1315
let path_len = definitions. def_path ( def_id) . data . len ( ) ;
1303
1316
self . cstore . update_extern_crate (
1304
1317
cnum,
1318
+ name,
1305
1319
ExternCrate {
1306
1320
src : ExternCrateSource :: Extern ( def_id. to_def_id ( ) ) ,
1307
1321
span : item. span ,
@@ -1320,6 +1334,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
1320
1334
1321
1335
self . cstore . update_extern_crate (
1322
1336
cnum,
1337
+ name,
1323
1338
ExternCrate {
1324
1339
src : ExternCrateSource :: Path ,
1325
1340
span,
0 commit comments