@@ -32,7 +32,7 @@ use std::sync::Arc;
3232use  diagnostics:: { ImportSuggestion ,  LabelSuggestion ,  Suggestion } ; 
3333use  effective_visibilities:: EffectiveVisibilitiesVisitor ; 
3434use  errors:: { ParamKindInEnumDiscriminant ,  ParamKindInNonTrivialAnonConst } ; 
35- use  imports:: { Import ,  ImportData ,  ImportKind ,  NameResolution } ; 
35+ use  imports:: { Import ,  ImportData ,  ImportKind ,  NameResolution ,   PendingBinding } ; 
3636use  late:: { 
3737    ForwardGenericParamBanReason ,  HasGenericParams ,  PathSource ,  PatternSource , 
3838    UnnecessaryQualification , 
@@ -1025,23 +1025,26 @@ impl<'ra> NameBindingData<'ra> {
10251025    } 
10261026} 
10271027
1028- #[ derive( Default ,  Clone ) ]  
10291028struct  ExternPreludeEntry < ' ra >  { 
10301029    /// Binding from an `extern crate` item. 
10311030/// The boolean flag is true is `item_binding` is non-redundant, happens either when 
10321031/// `only_item` is true, or when `extern crate` introducing `item_binding` used renaming. 
10331032item_binding :  Option < ( NameBinding < ' ra > ,  /* introduced by item */  bool ) > , 
10341033    /// Binding from an `--extern` flag, lazily populated on first use. 
1035- flag_binding :  Cell < Option < NameBinding < ' ra > > > , 
1036-     /// There was no `--extern` flag introducing this name, 
1037- /// `flag_binding` doesn't need to be populated. 
1038- only_item :  bool , 
1034+ flag_binding :  Option < Cell < PendingBinding < ' ra > > > , 
10391035} 
10401036
10411037impl  ExternPreludeEntry < ' _ >  { 
10421038    fn  introduced_by_item ( & self )  -> bool  { 
10431039        matches ! ( self . item_binding,  Some ( ( _,  true ) ) ) 
10441040    } 
1041+ 
1042+     fn  flag ( )  -> Self  { 
1043+         ExternPreludeEntry  { 
1044+             item_binding :  None , 
1045+             flag_binding :  Some ( Cell :: new ( PendingBinding :: Pending ) ) , 
1046+         } 
1047+     } 
10451048} 
10461049
10471050struct  DeriveData  { 
@@ -1533,19 +1536,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15331536                    && let  name = Symbol :: intern ( name) 
15341537                    && name. can_be_raw ( ) 
15351538                { 
1536-                     Some ( ( Macros20NormalizedIdent :: with_dummy_span ( name) ,  Default :: default ( ) ) ) 
1539+                     let  ident = Macros20NormalizedIdent :: with_dummy_span ( name) ; 
1540+                     Some ( ( ident,  ExternPreludeEntry :: flag ( ) ) ) 
15371541                }  else  { 
15381542                    None 
15391543                } 
15401544            } ) 
15411545            . collect ( ) ; 
15421546
15431547        if  !attr:: contains_name ( attrs,  sym:: no_core)  { 
1544-             extern_prelude 
1545-                  . insert ( Macros20NormalizedIdent :: with_dummy_span ( sym :: core ) ,   Default :: default ( ) ) ; 
1548+             let  ident =  Macros20NormalizedIdent :: with_dummy_span ( sym :: core ) ; 
1549+             extern_prelude . insert ( ident ,   ExternPreludeEntry :: flag ( ) ) ; 
15461550            if  !attr:: contains_name ( attrs,  sym:: no_std)  { 
1547-                 extern_prelude 
1548-                      . insert ( Macros20NormalizedIdent :: with_dummy_span ( sym :: std ) ,   Default :: default ( ) ) ; 
1551+                 let  ident =  Macros20NormalizedIdent :: with_dummy_span ( sym :: std ) ; 
1552+                 extern_prelude . insert ( ident ,   ExternPreludeEntry :: flag ( ) ) ; 
15491553            } 
15501554        } 
15511555
@@ -2240,31 +2244,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22402244
22412245    fn  extern_prelude_get_flag ( & self ,  ident :  Ident ,  finalize :  bool )  -> Option < NameBinding < ' ra > >  { 
22422246        let  entry = self . extern_prelude . get ( & Macros20NormalizedIdent :: new ( ident) ) ; 
2243-         entry. and_then ( |entry| match  entry. flag_binding . get ( )  { 
2244-             Some ( binding)  => { 
2245-                 if  finalize { 
2246-                     self . cstore_mut ( ) . process_path_extern ( self . tcx ,  ident. name ,  ident. span ) ; 
2247+         entry. and_then ( |entry| entry. flag_binding . as_ref ( ) ) . and_then ( |flag_binding| { 
2248+             let  binding = match  flag_binding. get ( )  { 
2249+                 PendingBinding :: Ready ( binding)  => { 
2250+                     if  finalize { 
2251+                         self . cstore_mut ( ) . process_path_extern ( self . tcx ,  ident. name ,  ident. span ) ; 
2252+                     } 
2253+                     binding
22472254                } 
2248-                 Some ( binding) 
2249-             } 
2250-             None  if  entry. only_item  => None , 
2251-             None  => { 
2252-                 let  crate_id = if  finalize { 
2253-                     self . cstore_mut ( ) . process_path_extern ( self . tcx ,  ident. name ,  ident. span ) 
2254-                 }  else  { 
2255-                     self . cstore_mut ( ) . maybe_process_path_extern ( self . tcx ,  ident. name ) 
2256-                 } ; 
2257-                 match  crate_id { 
2258-                     Some ( crate_id)  => { 
2255+                 PendingBinding :: Pending  => { 
2256+                     let  crate_id = if  finalize { 
2257+                         self . cstore_mut ( ) . process_path_extern ( self . tcx ,  ident. name ,  ident. span ) 
2258+                     }  else  { 
2259+                         self . cstore_mut ( ) . maybe_process_path_extern ( self . tcx ,  ident. name ) 
2260+                     } ; 
2261+                     crate_id. map ( |crate_id| { 
22592262                        let  res = Res :: Def ( DefKind :: Mod ,  crate_id. as_def_id ( ) ) ; 
2260-                         let  binding =
2261-                             self . arenas . new_pub_res_binding ( res,  DUMMY_SP ,  LocalExpnId :: ROOT ) ; 
2262-                         entry. flag_binding . set ( Some ( binding) ) ; 
2263-                         Some ( binding) 
2264-                     } 
2265-                     None  => finalize. then_some ( self . dummy_binding ) , 
2263+                         self . arenas . new_pub_res_binding ( res,  DUMMY_SP ,  LocalExpnId :: ROOT ) 
2264+                     } ) 
22662265                } 
2267-             } 
2266+             } ; 
2267+             flag_binding. set ( PendingBinding :: Ready ( binding) ) ; 
2268+             binding. or_else ( || finalize. then_some ( self . dummy_binding ) ) 
22682269        } ) 
22692270    } 
22702271
0 commit comments