@@ -32,7 +32,7 @@ use std::sync::Arc;
32
32
use diagnostics:: { ImportSuggestion , LabelSuggestion , Suggestion } ;
33
33
use effective_visibilities:: EffectiveVisibilitiesVisitor ;
34
34
use errors:: { ParamKindInEnumDiscriminant , ParamKindInNonTrivialAnonConst } ;
35
- use imports:: { Import , ImportData , ImportKind , NameResolution } ;
35
+ use imports:: { Import , ImportData , ImportKind , NameResolution , PendingBinding } ;
36
36
use late:: {
37
37
ForwardGenericParamBanReason , HasGenericParams , PathSource , PatternSource ,
38
38
UnnecessaryQualification ,
@@ -1025,23 +1025,26 @@ impl<'ra> NameBindingData<'ra> {
1025
1025
}
1026
1026
}
1027
1027
1028
- #[ derive( Default , Clone ) ]
1029
1028
struct ExternPreludeEntry < ' ra > {
1030
1029
/// Binding from an `extern crate` item.
1031
1030
/// The boolean flag is true is `item_binding` is non-redundant, happens either when
1032
1031
/// `only_item` is true, or when `extern crate` introducing `item_binding` used renaming.
1033
1032
item_binding : Option < ( NameBinding < ' ra > , /* introduced by item */ bool ) > ,
1034
1033
/// 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 > > > ,
1039
1035
}
1040
1036
1041
1037
impl ExternPreludeEntry < ' _ > {
1042
1038
fn introduced_by_item ( & self ) -> bool {
1043
1039
matches ! ( self . item_binding, Some ( ( _, true ) ) )
1044
1040
}
1041
+
1042
+ fn flag ( ) -> Self {
1043
+ ExternPreludeEntry {
1044
+ item_binding : None ,
1045
+ flag_binding : Some ( Cell :: new ( PendingBinding :: Pending ) ) ,
1046
+ }
1047
+ }
1045
1048
}
1046
1049
1047
1050
struct DeriveData {
@@ -1533,19 +1536,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1533
1536
&& let name = Symbol :: intern ( name)
1534
1537
&& name. can_be_raw ( )
1535
1538
{
1536
- Some ( ( Macros20NormalizedIdent :: with_dummy_span ( name) , Default :: default ( ) ) )
1539
+ let ident = Macros20NormalizedIdent :: with_dummy_span ( name) ;
1540
+ Some ( ( ident, ExternPreludeEntry :: flag ( ) ) )
1537
1541
} else {
1538
1542
None
1539
1543
}
1540
1544
} )
1541
1545
. collect ( ) ;
1542
1546
1543
1547
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 ( ) ) ;
1546
1550
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 ( ) ) ;
1549
1553
}
1550
1554
}
1551
1555
@@ -2240,31 +2244,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
2240
2244
2241
2245
fn extern_prelude_get_flag ( & self , ident : Ident , finalize : bool ) -> Option < NameBinding < ' ra > > {
2242
2246
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
2247
2254
}
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| {
2259
2262
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
+ } )
2266
2265
}
2267
- }
2266
+ } ;
2267
+ flag_binding. set ( PendingBinding :: Ready ( binding) ) ;
2268
+ binding. or_else ( || finalize. then_some ( self . dummy_binding ) )
2268
2269
} )
2269
2270
}
2270
2271
0 commit comments