@@ -1357,7 +1357,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1357
1357
/// On success, returns the resolved module, and the closest *private*
1358
1358
/// module found to the destination when resolving this path.
1359
1359
fn resolve_module_path ( & mut self ,
1360
- module_ : Module < ' a > ,
1361
1360
module_path : & [ Name ] ,
1362
1361
use_lexical_scope : UseLexicalScopeFlag ,
1363
1362
span : Span )
@@ -1368,10 +1367,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1368
1367
1369
1368
debug ! ( "(resolving module path for import) processing `{}` rooted at `{}`" ,
1370
1369
names_to_string( module_path) ,
1371
- module_to_string( & module_ ) ) ;
1370
+ module_to_string( self . current_module ) ) ;
1372
1371
1373
1372
// Resolve the module prefix, if any.
1374
- let module_prefix_result = self . resolve_module_prefix ( module_ , module_path) ;
1373
+ let module_prefix_result = self . resolve_module_prefix ( module_path) ;
1375
1374
1376
1375
let search_module;
1377
1376
let start_index;
@@ -1413,8 +1412,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1413
1412
// This is not a crate-relative path. We resolve the
1414
1413
// first component of the path in the current lexical
1415
1414
// scope and then proceed to resolve below that.
1416
- match self . resolve_item_in_lexical_scope ( module_,
1417
- module_path[ 0 ] ,
1415
+ match self . resolve_item_in_lexical_scope ( module_path[ 0 ] ,
1418
1416
TypeNS ,
1419
1417
true ) {
1420
1418
Failed ( err) => return Failed ( err) ,
@@ -1448,61 +1446,30 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1448
1446
/// Invariant: This must only be called during main resolution, not during
1449
1447
/// import resolution.
1450
1448
fn resolve_item_in_lexical_scope ( & mut self ,
1451
- module_ : Module < ' a > ,
1452
1449
name : Name ,
1453
1450
namespace : Namespace ,
1454
1451
record_used : bool )
1455
1452
-> ResolveResult < & ' a NameBinding < ' a > > {
1456
- debug ! ( "(resolving item in lexical scope) resolving `{}` in namespace {:?} in `{}`" ,
1457
- name,
1458
- namespace,
1459
- module_to_string( & module_) ) ;
1460
-
1461
- // Proceed up the scope chain looking for parent modules.
1462
- let mut search_module = module_;
1463
- loop {
1464
- // Resolve the name in the parent module.
1465
- match self . resolve_name_in_module ( search_module, name, namespace, true , record_used) {
1466
- Failed ( Some ( ( span, msg) ) ) => {
1467
- resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
1468
- }
1469
- Failed ( None ) => ( ) , // Continue up the search chain.
1470
- Indeterminate => {
1471
- // We couldn't see through the higher scope because of an
1472
- // unresolved import higher up. Bail.
1473
-
1474
- debug ! ( "(resolving item in lexical scope) indeterminate higher scope; bailing" ) ;
1475
- return Indeterminate ;
1476
- }
1477
- Success ( binding) => {
1478
- // We found the module.
1479
- debug ! ( "(resolving item in lexical scope) found name in module, done" ) ;
1480
- return Success ( binding) ;
1481
- }
1453
+ // Check the local set of ribs.
1454
+ for i in ( 0 .. self . get_ribs ( namespace) . len ( ) ) . rev ( ) {
1455
+ if let Some ( _) = self . get_ribs ( namespace) [ i] . bindings . get ( & name) . cloned ( ) {
1456
+ return Failed ( None ) ;
1482
1457
}
1483
1458
1484
- // Go to the next parent.
1485
- match search_module. parent_link {
1486
- NoParentLink => {
1487
- // No more parents. This module was unresolved.
1488
- debug ! ( "(resolving item in lexical scope) unresolved module: no parent module" ) ;
1489
- return Failed ( None ) ;
1490
- }
1491
- ModuleParentLink ( parent_module_node, _) => {
1492
- if search_module. is_normal ( ) {
1493
- // We stop the search here.
1494
- debug ! ( "(resolving item in lexical scope) unresolved module: not \
1495
- searching through module parents") ;
1496
- return Failed ( None ) ;
1497
- } else {
1498
- search_module = parent_module_node;
1499
- }
1500
- }
1501
- BlockParentLink ( parent_module_node, _) => {
1502
- search_module = parent_module_node;
1459
+ if let ModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
1460
+ if let Success ( binding) = self . resolve_name_in_module ( module,
1461
+ name,
1462
+ namespace,
1463
+ true ,
1464
+ record_used) {
1465
+ return Success ( binding) ;
1503
1466
}
1467
+ // We can only see through anonymous modules
1468
+ if module. def . is_some ( ) { return Failed ( None ) ; }
1504
1469
}
1505
1470
}
1471
+
1472
+ Failed ( None )
1506
1473
}
1507
1474
1508
1475
/// Returns the nearest normal module parent of the given module.
@@ -1538,9 +1505,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1538
1505
/// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
1539
1506
/// (b) some chain of `super::`.
1540
1507
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
1541
- fn resolve_module_prefix ( & mut self ,
1542
- module_ : Module < ' a > ,
1543
- module_path : & [ Name ] )
1508
+ fn resolve_module_prefix ( & mut self , module_path : & [ Name ] )
1544
1509
-> ResolveResult < ModulePrefixResult < ' a > > {
1545
1510
// Start at the current module if we see `self` or `super`, or at the
1546
1511
// top of the crate otherwise.
@@ -1549,6 +1514,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1549
1514
"super" => 0 ,
1550
1515
_ => return Success ( NoPrefixFound ) ,
1551
1516
} ;
1517
+ let module_ = self . current_module ;
1552
1518
let mut containing_module = self . get_nearest_normal_module_parent_or_self ( module_) ;
1553
1519
1554
1520
// Now loop through all the `super`s we find.
@@ -2594,8 +2560,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2594
2560
name : Name ,
2595
2561
span : Span )
2596
2562
-> BareIdentifierPatternResolution {
2597
- let module = self . current_module ;
2598
- match self . resolve_item_in_lexical_scope ( module, name, ValueNS , true ) {
2563
+ match self . resolve_item_in_lexical_scope ( name, ValueNS , true ) {
2599
2564
Success ( binding) => {
2600
2565
debug ! ( "(resolve bare identifier pattern) succeeded in finding {} at {:?}" ,
2601
2566
name,
@@ -2754,9 +2719,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2754
2719
}
2755
2720
2756
2721
// Check the items.
2757
- let module = self . current_module ;
2758
2722
let name = identifier. unhygienic_name ;
2759
- match self . resolve_item_in_lexical_scope ( module , name, namespace, record_used) {
2723
+ match self . resolve_item_in_lexical_scope ( name, namespace, record_used) {
2760
2724
Success ( binding) => binding. def ( ) . map ( LocalDef :: from_def) ,
2761
2725
Failed ( Some ( ( span, msg) ) ) => {
2762
2726
resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
@@ -2869,8 +2833,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2869
2833
. collect :: < Vec < _ > > ( ) ;
2870
2834
2871
2835
let containing_module;
2872
- let current_module = self . current_module ;
2873
- match self . resolve_module_path ( current_module, & module_path, UseLexicalScope , span) {
2836
+ match self . resolve_module_path ( & module_path, UseLexicalScope , span) {
2874
2837
Failed ( err) => {
2875
2838
let ( span, msg) = match err {
2876
2839
Some ( ( span, msg) ) => ( span, msg) ,
@@ -3024,7 +2987,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3024
2987
span : Span ,
3025
2988
name_path : & [ ast:: Name ] )
3026
2989
-> Option < Module < ' a > > {
3027
- let root = this. current_module ;
3028
2990
let last_name = name_path. last ( ) . unwrap ( ) ;
3029
2991
3030
2992
if name_path. len ( ) == 1 {
@@ -3034,7 +2996,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3034
2996
. and_then ( NameBinding :: module)
3035
2997
}
3036
2998
} else {
3037
- this. resolve_module_path ( root , & name_path, UseLexicalScope , span) . success ( )
2999
+ this. resolve_module_path ( & name_path, UseLexicalScope , span) . success ( )
3038
3000
}
3039
3001
}
3040
3002
@@ -3274,10 +3236,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3274
3236
let name_path = path. segments . iter ( )
3275
3237
. map ( |seg| seg. identifier . name )
3276
3238
. collect :: < Vec < _ > > ( ) ;
3277
- let current_module = self . current_module ;
3278
3239
3279
- match self . resolve_module_path ( current_module,
3280
- & name_path[ ..] ,
3240
+ match self . resolve_module_path ( & name_path[ ..] ,
3281
3241
UseLexicalScope ,
3282
3242
expr. span ) {
3283
3243
Success ( _) => {
0 commit comments