@@ -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_expand:: base:: SyntaxExtension ;
16
17
use rustc_fs_util:: try_canonicalize;
17
18
use rustc_hir as hir;
@@ -69,6 +70,9 @@ pub struct CStore {
69
70
/// This crate has a `#[alloc_error_handler]` item.
70
71
has_alloc_error_handler : bool ,
71
72
73
+ /// Names that were used to load the crates via `extern crate` or paths.
74
+ resolved_externs : UnordMap < Symbol , CrateNum > ,
75
+
72
76
/// Unused externs of the crate
73
77
unused_externs : Vec < Symbol > ,
74
78
@@ -249,6 +253,14 @@ impl CStore {
249
253
self . metas [ cnum] = Some ( Box :: new ( data) ) ;
250
254
}
251
255
256
+ /// Save the name used to resolve the extern crate in the local crate
257
+ ///
258
+ /// The name isn't always the crate's own name, because `sess.opts.externs` can assign it another name.
259
+ /// It's also not always the same as the `DefId`'s symbol due to renames `extern crate resolved_name as defid_name`.
260
+ pub ( crate ) fn set_resolved_extern_crate_name ( & mut self , name : Symbol , extern_crate : CrateNum ) {
261
+ self . resolved_externs . insert ( name, extern_crate) ;
262
+ }
263
+
252
264
pub ( crate ) fn iter_crate_data ( & self ) -> impl Iterator < Item = ( CrateNum , & CrateMetadata ) > {
253
265
self . metas
254
266
. iter_enumerated ( )
@@ -475,6 +487,7 @@ impl CStore {
475
487
alloc_error_handler_kind : None ,
476
488
has_global_allocator : false ,
477
489
has_alloc_error_handler : false ,
490
+ resolved_externs : UnordMap :: default ( ) ,
478
491
unused_externs : Vec :: new ( ) ,
479
492
used_extern_options : Default :: default ( ) ,
480
493
}
@@ -1308,6 +1321,7 @@ impl CStore {
1308
1321
let path_len = definitions. def_path ( def_id) . data . len ( ) ;
1309
1322
self . update_extern_crate (
1310
1323
cnum,
1324
+ name,
1311
1325
ExternCrate {
1312
1326
src : ExternCrateSource :: Extern ( def_id. to_def_id ( ) ) ,
1313
1327
span : item. span ,
@@ -1332,6 +1346,7 @@ impl CStore {
1332
1346
1333
1347
self . update_extern_crate (
1334
1348
cnum,
1349
+ name,
1335
1350
ExternCrate {
1336
1351
src : ExternCrateSource :: Path ,
1337
1352
span,
0 commit comments