@@ -126,7 +126,7 @@ enum ResolutionError<'a> {
126126 /// error E0413: cannot be named the same as an enum variant or unit-like struct in scope
127127 DeclarationShadowsEnumVariantOrUnitLikeStruct ( Name ) ,
128128 /// error E0414: only irrefutable patterns allowed here
129- ConstantForIrrefutableBinding ( Name ) ,
129+ ConstantForIrrefutableBinding ( Name , & ' a NameBinding < ' a > ) ,
130130 /// error E0415: identifier is bound more than once in this parameter list
131131 IdentifierBoundMoreThanOnceInParameterList ( & ' a str ) ,
132132 /// 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>,
317317 & format ! ( "has same name as enum variant or unit-like struct" ) ) ;
318318 err
319319 }
320- ResolutionError :: ConstantForIrrefutableBinding ( name) => {
320+ ResolutionError :: ConstantForIrrefutableBinding ( name, binding ) => {
321321 let mut err = struct_span_err ! ( resolver. session,
322322 span,
323323 E0414 ,
324324 "let variables cannot be named the same as const variables" ) ;
325325 err. span_label ( span,
326326 & 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) ) ;
333329 err
334330 }
335331 ResolutionError :: IdentifierBoundMoreThanOnceInParameterList ( identifier) => {
@@ -714,9 +710,9 @@ enum AssocItemResolveResult {
714710}
715711
716712#[ derive( Copy , Clone ) ]
717- enum BareIdentifierPatternResolution {
713+ enum BareIdentifierPatternResolution < ' a > {
718714 FoundStructOrEnumVariant ( Def ) ,
719- FoundConst ( Def , Name ) ,
715+ FoundConst ( & ' a NameBinding < ' a > , Name ) ,
720716 BareIdentifierPatternUnresolved ,
721717}
722718
@@ -1456,7 +1452,12 @@ impl<'a> Resolver<'a> {
14561452 }
14571453
14581454 // 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+ }
14601461 }
14611462 }
14621463
@@ -1543,11 +1544,7 @@ impl<'a> Resolver<'a> {
15431544 debug ! ( "(resolving name in module) resolving `{}` in `{}`" , name, module_to_string( module) ) ;
15441545
15451546 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| {
15511548 if record_used {
15521549 if let NameBindingKind :: Import { directive, .. } = binding. kind {
15531550 self . used_imports . insert ( ( directive. id , namespace) ) ;
@@ -2289,21 +2286,21 @@ impl<'a> Resolver<'a> {
22892286 ) ;
22902287 self . record_def ( pattern. id , err_path_resolution ( ) ) ;
22912288 }
2292- FoundConst ( def , _) if const_ok => {
2289+ FoundConst ( binding , _) if const_ok => {
22932290 debug ! ( "(resolving pattern) resolving `{}` to constant" , renamed) ;
22942291
22952292 self . enforce_default_binding_mode ( pattern, binding_mode, "a constant" ) ;
22962293 self . record_def ( pattern. id ,
22972294 PathResolution {
2298- base_def : def,
2295+ base_def : binding . def ( ) . unwrap ( ) ,
22992296 depth : 0 ,
23002297 } ) ;
23012298 }
2302- FoundConst ( _ , name) => {
2299+ FoundConst ( binding , name) => {
23032300 resolve_error (
23042301 self ,
23052302 pattern. span ,
2306- ResolutionError :: ConstantForIrrefutableBinding ( name)
2303+ ResolutionError :: ConstantForIrrefutableBinding ( name, binding )
23072304 ) ;
23082305 self . record_def ( pattern. id , err_path_resolution ( ) ) ;
23092306 }
@@ -2526,7 +2523,7 @@ impl<'a> Resolver<'a> {
25262523 }
25272524
25282525 fn resolve_bare_identifier_pattern ( & mut self , ident : ast:: Ident , span : Span )
2529- -> BareIdentifierPatternResolution {
2526+ -> BareIdentifierPatternResolution < ' a > {
25302527 let binding = match self . resolve_ident_in_lexical_scope ( ident, ValueNS , true ) {
25312528 Some ( LexicalScopeBinding :: Item ( binding) ) => binding,
25322529 _ => return BareIdentifierPatternUnresolved ,
@@ -2535,7 +2532,7 @@ impl<'a> Resolver<'a> {
25352532
25362533 match def {
25372534 Def :: Variant ( ..) | Def :: Struct ( ..) => FoundStructOrEnumVariant ( def) ,
2538- Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( def , ident. name ) ,
2535+ Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( binding , ident. name ) ,
25392536 Def :: Static ( ..) => {
25402537 let error = ResolutionError :: StaticVariableReference ( binding) ;
25412538 resolve_error ( self , span, error) ;
0 commit comments