@@ -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
@@ -1456,7 +1452,12 @@ impl<'a> Resolver<'a> {
1456
1452
}
1457
1453
1458
1454
// We can only see through anonymous modules
1459
- if module. def . is_some ( ) { return None ; }
1455
+ if module. def . is_some ( ) {
1456
+ return module. prelude . borrow ( ) . and_then ( |module| {
1457
+ module. resolve_name ( name, ns, false )
1458
+ . success ( ) . map ( LexicalScopeBinding :: Item )
1459
+ } ) ;
1460
+ }
1460
1461
}
1461
1462
}
1462
1463
@@ -1543,11 +1544,7 @@ impl<'a> Resolver<'a> {
1543
1544
debug ! ( "(resolving name in module) resolving `{}` in `{}`" , name, module_to_string( module) ) ;
1544
1545
1545
1546
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| {
1547
+ module. resolve_name ( name, namespace, use_lexical_scope) . and_then ( |binding| {
1551
1548
if record_used {
1552
1549
if let NameBindingKind :: Import { directive, .. } = binding. kind {
1553
1550
self . used_imports . insert ( ( directive. id , namespace) ) ;
@@ -2289,21 +2286,21 @@ impl<'a> Resolver<'a> {
2289
2286
) ;
2290
2287
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2291
2288
}
2292
- FoundConst ( def , _) if const_ok => {
2289
+ FoundConst ( binding , _) if const_ok => {
2293
2290
debug ! ( "(resolving pattern) resolving `{}` to constant" , renamed) ;
2294
2291
2295
2292
self . enforce_default_binding_mode ( pattern, binding_mode, "a constant" ) ;
2296
2293
self . record_def ( pattern. id ,
2297
2294
PathResolution {
2298
- base_def : def,
2295
+ base_def : binding . def ( ) . unwrap ( ) ,
2299
2296
depth : 0 ,
2300
2297
} ) ;
2301
2298
}
2302
- FoundConst ( _ , name) => {
2299
+ FoundConst ( binding , name) => {
2303
2300
resolve_error (
2304
2301
self ,
2305
2302
pattern. span ,
2306
- ResolutionError :: ConstantForIrrefutableBinding ( name)
2303
+ ResolutionError :: ConstantForIrrefutableBinding ( name, binding )
2307
2304
) ;
2308
2305
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2309
2306
}
@@ -2526,7 +2523,7 @@ impl<'a> Resolver<'a> {
2526
2523
}
2527
2524
2528
2525
fn resolve_bare_identifier_pattern ( & mut self , ident : ast:: Ident , span : Span )
2529
- -> BareIdentifierPatternResolution {
2526
+ -> BareIdentifierPatternResolution < ' a > {
2530
2527
let binding = match self . resolve_ident_in_lexical_scope ( ident, ValueNS , true ) {
2531
2528
Some ( LexicalScopeBinding :: Item ( binding) ) => binding,
2532
2529
_ => return BareIdentifierPatternUnresolved ,
@@ -2535,7 +2532,7 @@ impl<'a> Resolver<'a> {
2535
2532
2536
2533
match def {
2537
2534
Def :: Variant ( ..) | Def :: Struct ( ..) => FoundStructOrEnumVariant ( def) ,
2538
- Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( def , ident. name ) ,
2535
+ Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( binding , ident. name ) ,
2539
2536
Def :: Static ( ..) => {
2540
2537
let error = ResolutionError :: StaticVariableReference ( binding) ;
2541
2538
resolve_error ( self , span, error) ;
0 commit comments