@@ -12,6 +12,7 @@ use rustc_data_structures::fx::FxHashSet;
1212use rustc_data_structures:: owned_slice:: OwnedSlice ;
1313use rustc_data_structures:: svh:: Svh ;
1414use rustc_data_structures:: sync:: { self , FreezeReadGuard , FreezeWriteGuard } ;
15+ use rustc_data_structures:: unord:: UnordMap ;
1516use rustc_expand:: base:: SyntaxExtension ;
1617use rustc_fs_util:: try_canonicalize;
1718use rustc_hir as hir;
@@ -69,6 +70,9 @@ pub struct CStore {
6970 /// This crate has a `#[alloc_error_handler]` item.
7071 has_alloc_error_handler : bool ,
7172
73+ /// Names that were used to load the crates via `extern crate` or paths.
74+ resolved_externs : UnordMap < Symbol , CrateNum > ,
75+
7276 /// Unused externs of the crate
7377 unused_externs : Vec < Symbol > ,
7478
@@ -249,6 +253,14 @@ impl CStore {
249253 self . metas [ cnum] = Some ( Box :: new ( data) ) ;
250254 }
251255
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+
252264 pub ( crate ) fn iter_crate_data ( & self ) -> impl Iterator < Item = ( CrateNum , & CrateMetadata ) > {
253265 self . metas
254266 . iter_enumerated ( )
@@ -475,6 +487,7 @@ impl CStore {
475487 alloc_error_handler_kind : None ,
476488 has_global_allocator : false ,
477489 has_alloc_error_handler : false ,
490+ resolved_externs : UnordMap :: default ( ) ,
478491 unused_externs : Vec :: new ( ) ,
479492 used_extern_options : Default :: default ( ) ,
480493 }
@@ -1308,6 +1321,7 @@ impl CStore {
13081321 let path_len = definitions. def_path ( def_id) . data . len ( ) ;
13091322 self . update_extern_crate (
13101323 cnum,
1324+ name,
13111325 ExternCrate {
13121326 src : ExternCrateSource :: Extern ( def_id. to_def_id ( ) ) ,
13131327 span : item. span ,
@@ -1332,6 +1346,7 @@ impl CStore {
13321346
13331347 self . update_extern_crate (
13341348 cnum,
1349+ name,
13351350 ExternCrate {
13361351 src : ExternCrateSource :: Path ,
13371352 span,
0 commit comments