@@ -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_errors:: DiagCtxtHandle ;
1617use rustc_expand:: base:: SyntaxExtension ;
1718use rustc_fs_util:: try_canonicalize;
@@ -68,6 +69,9 @@ pub struct CStore {
6869 /// This crate has a `#[alloc_error_handler]` item.
6970 has_alloc_error_handler : bool ,
7071
72+ /// Names that were used to load the crates via `extern crate` or paths.
73+ resolved_externs : UnordMap < Symbol , CrateNum > ,
74+
7175 /// Unused externs of the crate
7276 unused_externs : Vec < Symbol > ,
7377}
@@ -268,6 +272,14 @@ impl CStore {
268272 self . metas [ cnum] = Some ( Box :: new ( data) ) ;
269273 }
270274
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 resolved_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+
271283 pub ( crate ) fn iter_crate_data ( & self ) -> impl Iterator < Item = ( CrateNum , & CrateMetadata ) > {
272284 self . metas
273285 . iter_enumerated ( )
@@ -494,6 +506,7 @@ impl CStore {
494506 alloc_error_handler_kind : None ,
495507 has_global_allocator : false ,
496508 has_alloc_error_handler : false ,
509+ resolved_externs : UnordMap :: default ( ) ,
497510 unused_externs : Vec :: new ( ) ,
498511 }
499512 }
@@ -1302,6 +1315,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
13021315 let path_len = definitions. def_path ( def_id) . data . len ( ) ;
13031316 self . cstore . update_extern_crate (
13041317 cnum,
1318+ name,
13051319 ExternCrate {
13061320 src : ExternCrateSource :: Extern ( def_id. to_def_id ( ) ) ,
13071321 span : item. span ,
@@ -1320,6 +1334,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
13201334
13211335 self . cstore . update_extern_crate (
13221336 cnum,
1337+ name,
13231338 ExternCrate {
13241339 src : ExternCrateSource :: Path ,
13251340 span,
0 commit comments