@@ -968,7 +968,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
968968 }
969969 self . r . potentially_unused_imports . push ( import) ;
970970 let imported_binding = self . r . import ( binding, import) ;
971- if parent == self . r . graph_root {
971+ if ident . name != kw :: Underscore && parent == self . r . graph_root {
972972 let ident = ident. normalize_to_macros_2_0 ( ) ;
973973 if let Some ( entry) = self . r . extern_prelude . get ( & ident)
974974 && expansion != LocalExpnId :: ROOT
@@ -984,23 +984,29 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
984984 // more details: https://github.com/rust-lang/rust/pull/111761
985985 return ;
986986 }
987- let entry = self . r . extern_prelude . entry ( ident) . or_insert ( ExternPreludeEntry {
988- binding : Cell :: new ( None ) ,
989- introduced_by_item : true ,
990- } ) ;
991- if orig_name. is_some ( ) {
992- entry. introduced_by_item = true ;
993- }
994- // Binding from `extern crate` item in source code can replace
995- // a binding from `--extern` on command line here.
996- if !entry. is_import ( ) {
997- entry. binding . set ( Some ( imported_binding) ) ;
998- } else if ident. name != kw:: Underscore {
999- self . r . dcx ( ) . span_delayed_bug (
1000- item. span ,
1001- format ! ( "it had been define the external module '{ident}' multiple times" ) ,
1002- ) ;
1003- }
987+
988+ use indexmap:: map:: Entry ;
989+ match self . r . extern_prelude . entry ( ident) {
990+ Entry :: Occupied ( mut occupied) => {
991+ let entry = occupied. get_mut ( ) ;
992+ if let Some ( old_binding) = entry. binding . get ( )
993+ && old_binding. is_import ( )
994+ {
995+ let msg = format ! ( "extern crate `{ident}` already in extern prelude" ) ;
996+ self . r . tcx . dcx ( ) . span_delayed_bug ( item. span , msg) ;
997+ } else {
998+ // Binding from `extern crate` item in source code can replace
999+ // a binding from `--extern` on command line here.
1000+ entry. binding . set ( Some ( imported_binding) ) ;
1001+ entry. introduced_by_item = orig_name. is_some ( ) ;
1002+ }
1003+ entry
1004+ }
1005+ Entry :: Vacant ( vacant) => vacant. insert ( ExternPreludeEntry {
1006+ binding : Cell :: new ( Some ( imported_binding) ) ,
1007+ introduced_by_item : true ,
1008+ } ) ,
1009+ } ;
10041010 }
10051011 self . r . define_binding_local ( parent, ident, TypeNS , imported_binding) ;
10061012 }
0 commit comments