@@ -126,7 +126,7 @@ enum ResolutionError<'a> {
126
126
/// error E0413: cannot be named the same as an enum variant or unit-like struct in scope
127
127
DeclarationShadowsEnumVariantOrUnitLikeStruct ( Name ) ,
128
128
/// error E0414: only irrefutable patterns allowed here
129
- ConstantForIrrefutableBinding ( Name ) ,
129
+ ConstantForIrrefutableBinding ( Name , & ' a NameBinding < ' a > ) ,
130
130
/// error E0415: identifier is bound more than once in this parameter list
131
131
IdentifierBoundMoreThanOnceInParameterList ( & ' a str ) ,
132
132
/// error E0416: identifier is bound more than once in the same pattern
@@ -317,19 +317,15 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
317
317
& format ! ( "has same name as enum variant or unit-like struct" ) ) ;
318
318
err
319
319
}
320
- ResolutionError :: ConstantForIrrefutableBinding ( name) => {
320
+ ResolutionError :: ConstantForIrrefutableBinding ( name, binding ) => {
321
321
let mut err = struct_span_err ! ( resolver. session,
322
322
span,
323
323
E0414 ,
324
324
"let variables cannot be named the same as const variables" ) ;
325
325
err. span_label ( span,
326
326
& format ! ( "cannot be named the same as a const variable" ) ) ;
327
- if let Some ( binding) = resolver. current_module
328
- . resolve_name_in_lexical_scope ( name, ValueNS ) {
329
- let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
330
- err. span_label ( binding. span , & format ! ( "a constant `{}` is {} here" ,
331
- name, participle) ) ;
332
- }
327
+ let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
328
+ err. span_label ( binding. span , & format ! ( "a constant `{}` is {} here" , name, participle) ) ;
333
329
err
334
330
}
335
331
ResolutionError :: IdentifierBoundMoreThanOnceInParameterList ( identifier) => {
@@ -714,9 +710,9 @@ enum AssocItemResolveResult {
714
710
}
715
711
716
712
#[ derive( Copy , Clone ) ]
717
- enum BareIdentifierPatternResolution {
713
+ enum BareIdentifierPatternResolution < ' a > {
718
714
FoundStructOrEnumVariant ( Def ) ,
719
- FoundConst ( Def , Name ) ,
715
+ FoundConst ( & ' a NameBinding < ' a > , Name ) ,
720
716
BareIdentifierPatternUnresolved ,
721
717
}
722
718
@@ -792,7 +788,7 @@ pub struct ModuleS<'a> {
792
788
resolutions : RefCell < HashMap < ( Name , Namespace ) , & ' a RefCell < NameResolution < ' a > > > > ,
793
789
unresolved_imports : RefCell < Vec < & ' a ImportDirective < ' a > > > ,
794
790
795
- prelude : RefCell < Option < Module < ' a > > > ,
791
+ no_implicit_prelude : Cell < bool > ,
796
792
797
793
glob_importers : RefCell < Vec < ( Module < ' a > , & ' a ImportDirective < ' a > ) > > ,
798
794
globs : RefCell < Vec < & ' a ImportDirective < ' a > > > ,
@@ -821,7 +817,7 @@ impl<'a> ModuleS<'a> {
821
817
extern_crate_id : None ,
822
818
resolutions : RefCell :: new ( HashMap :: new ( ) ) ,
823
819
unresolved_imports : RefCell :: new ( Vec :: new ( ) ) ,
824
- prelude : RefCell :: new ( None ) ,
820
+ no_implicit_prelude : Cell :: new ( false ) ,
825
821
glob_importers : RefCell :: new ( Vec :: new ( ) ) ,
826
822
globs : RefCell :: new ( ( Vec :: new ( ) ) ) ,
827
823
traits : RefCell :: new ( None ) ,
@@ -985,6 +981,8 @@ pub struct Resolver<'a> {
985
981
986
982
graph_root : Module < ' a > ,
987
983
984
+ prelude : Option < Module < ' a > > ,
985
+
988
986
trait_item_map : FnvHashMap < ( Name , DefId ) , bool /* is static method? */ > ,
989
987
990
988
structs : FnvHashMap < DefId , Vec < Name > > ,
@@ -1174,6 +1172,7 @@ impl<'a> Resolver<'a> {
1174
1172
// The outermost module has def ID 0; this is not reflected in the
1175
1173
// AST.
1176
1174
graph_root : graph_root,
1175
+ prelude : None ,
1177
1176
1178
1177
trait_item_map : FnvHashMap ( ) ,
1179
1178
structs : FnvHashMap ( ) ,
@@ -1456,7 +1455,15 @@ impl<'a> Resolver<'a> {
1456
1455
}
1457
1456
1458
1457
// We can only see through anonymous modules
1459
- if module. def . is_some ( ) { return None ; }
1458
+ if module. def . is_some ( ) {
1459
+ return match self . prelude {
1460
+ Some ( prelude) if !module. no_implicit_prelude . get ( ) => {
1461
+ prelude. resolve_name ( name, ns, false ) . success ( )
1462
+ . map ( LexicalScopeBinding :: Item )
1463
+ }
1464
+ _ => None ,
1465
+ } ;
1466
+ }
1460
1467
}
1461
1468
}
1462
1469
@@ -1543,11 +1550,7 @@ impl<'a> Resolver<'a> {
1543
1550
debug ! ( "(resolving name in module) resolving `{}` in `{}`" , name, module_to_string( module) ) ;
1544
1551
1545
1552
self . populate_module_if_necessary ( module) ;
1546
- match use_lexical_scope {
1547
- true => module. resolve_name_in_lexical_scope ( name, namespace)
1548
- . map ( Success ) . unwrap_or ( Failed ( None ) ) ,
1549
- false => module. resolve_name ( name, namespace, false ) ,
1550
- } . and_then ( |binding| {
1553
+ module. resolve_name ( name, namespace, use_lexical_scope) . and_then ( |binding| {
1551
1554
if record_used {
1552
1555
if let NameBindingKind :: Import { directive, .. } = binding. kind {
1553
1556
self . used_imports . insert ( ( directive. id , namespace) ) ;
@@ -2289,21 +2292,21 @@ impl<'a> Resolver<'a> {
2289
2292
) ;
2290
2293
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2291
2294
}
2292
- FoundConst ( def , _) if const_ok => {
2295
+ FoundConst ( binding , _) if const_ok => {
2293
2296
debug ! ( "(resolving pattern) resolving `{}` to constant" , renamed) ;
2294
2297
2295
2298
self . enforce_default_binding_mode ( pattern, binding_mode, "a constant" ) ;
2296
2299
self . record_def ( pattern. id ,
2297
2300
PathResolution {
2298
- base_def : def,
2301
+ base_def : binding . def ( ) . unwrap ( ) ,
2299
2302
depth : 0 ,
2300
2303
} ) ;
2301
2304
}
2302
- FoundConst ( _ , name) => {
2305
+ FoundConst ( binding , name) => {
2303
2306
resolve_error (
2304
2307
self ,
2305
2308
pattern. span ,
2306
- ResolutionError :: ConstantForIrrefutableBinding ( name)
2309
+ ResolutionError :: ConstantForIrrefutableBinding ( name, binding )
2307
2310
) ;
2308
2311
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2309
2312
}
@@ -2526,7 +2529,7 @@ impl<'a> Resolver<'a> {
2526
2529
}
2527
2530
2528
2531
fn resolve_bare_identifier_pattern ( & mut self , ident : ast:: Ident , span : Span )
2529
- -> BareIdentifierPatternResolution {
2532
+ -> BareIdentifierPatternResolution < ' a > {
2530
2533
let binding = match self . resolve_ident_in_lexical_scope ( ident, ValueNS , true ) {
2531
2534
Some ( LexicalScopeBinding :: Item ( binding) ) => binding,
2532
2535
_ => return BareIdentifierPatternUnresolved ,
@@ -2535,7 +2538,7 @@ impl<'a> Resolver<'a> {
2535
2538
2536
2539
match def {
2537
2540
Def :: Variant ( ..) | Def :: Struct ( ..) => FoundStructOrEnumVariant ( def) ,
2538
- Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( def , ident. name ) ,
2541
+ Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( binding , ident. name ) ,
2539
2542
Def :: Static ( ..) => {
2540
2543
let error = ResolutionError :: StaticVariableReference ( binding) ;
2541
2544
resolve_error ( self , span, error) ;
@@ -3264,7 +3267,7 @@ impl<'a> Resolver<'a> {
3264
3267
let mut search_module = self . current_module ;
3265
3268
loop {
3266
3269
// Look for trait children.
3267
- let mut search_in_module = |module : Module < ' a > | {
3270
+ let mut search_in_module = |this : & mut Self , module : Module < ' a > | {
3268
3271
let mut traits = module. traits . borrow_mut ( ) ;
3269
3272
if traits. is_none ( ) {
3270
3273
let mut collected_traits = Vec :: new ( ) ;
@@ -3279,23 +3282,25 @@ impl<'a> Resolver<'a> {
3279
3282
3280
3283
for & ( trait_name, binding) in traits. as_ref ( ) . unwrap ( ) . iter ( ) {
3281
3284
let trait_def_id = binding. def ( ) . unwrap ( ) . def_id ( ) ;
3282
- if self . trait_item_map . contains_key ( & ( name, trait_def_id) ) {
3285
+ if this . trait_item_map . contains_key ( & ( name, trait_def_id) ) {
3283
3286
let mut import_id = None ;
3284
3287
if let NameBindingKind :: Import { directive, .. } = binding. kind {
3285
3288
let id = directive. id ;
3286
- self . maybe_unused_trait_imports . insert ( id) ;
3289
+ this . maybe_unused_trait_imports . insert ( id) ;
3287
3290
import_id = Some ( id) ;
3288
3291
}
3289
3292
add_trait_info ( & mut found_traits, trait_def_id, import_id, name) ;
3290
- self . record_use ( trait_name, binding) ;
3293
+ this . record_use ( trait_name, binding) ;
3291
3294
}
3292
3295
}
3293
3296
} ;
3294
- search_in_module ( search_module) ;
3297
+ search_in_module ( self , search_module) ;
3295
3298
3296
3299
match search_module. parent_link {
3297
3300
NoParentLink | ModuleParentLink ( ..) => {
3298
- search_module. prelude . borrow ( ) . map ( search_in_module) ;
3301
+ if !search_module. no_implicit_prelude . get ( ) {
3302
+ self . prelude . map ( |prelude| search_in_module ( self , prelude) ) ;
3303
+ }
3299
3304
break ;
3300
3305
}
3301
3306
BlockParentLink ( parent_module, _) => {
0 commit comments