@@ -789,6 +789,26 @@ enum LexicalScopeBinding<'a> {
789
789
LocalDef ( LocalDef ) ,
790
790
}
791
791
792
+ impl < ' a > LexicalScopeBinding < ' a > {
793
+ fn local_def ( self ) -> LocalDef {
794
+ match self {
795
+ LexicalScopeBinding :: LocalDef ( local_def) => local_def,
796
+ LexicalScopeBinding :: Item ( binding) => LocalDef :: from_def ( binding. def ( ) . unwrap ( ) ) ,
797
+ }
798
+ }
799
+
800
+ fn def ( self ) -> Def {
801
+ self . local_def ( ) . def
802
+ }
803
+
804
+ fn module ( self ) -> Option < Module < ' a > > {
805
+ match self {
806
+ LexicalScopeBinding :: Item ( binding) => binding. module ( ) ,
807
+ _ => None ,
808
+ }
809
+ }
810
+ }
811
+
792
812
/// The link from a module up to its nearest parent node.
793
813
#[ derive( Clone , Debug ) ]
794
814
enum ParentLink < ' a > {
@@ -1404,20 +1424,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1404
1424
// This is not a crate-relative path. We resolve the
1405
1425
// first component of the path in the current lexical
1406
1426
// scope and then proceed to resolve below that.
1407
- match self . resolve_item_in_lexical_scope ( module_path[ 0 ] ,
1408
- TypeNS ,
1409
- true ) {
1410
- Failed ( err) => return Failed ( err) ,
1411
- Indeterminate => {
1412
- debug ! ( "(resolving module path for import) indeterminate; bailing" ) ;
1413
- return Indeterminate ;
1414
- }
1415
- Success ( binding) => match binding. module ( ) {
1416
- Some ( containing_module) => {
1417
- search_module = containing_module;
1418
- start_index = 1 ;
1419
- }
1420
- None => return Failed ( None ) ,
1427
+ let ident = hir:: Ident :: from_name ( module_path[ 0 ] ) ;
1428
+ match self . resolve_ident_in_lexical_scope ( ident, TypeNS , true )
1429
+ . and_then ( LexicalScopeBinding :: module) {
1430
+ None => return Failed ( None ) ,
1431
+ Some ( containing_module) => {
1432
+ search_module = containing_module;
1433
+ start_index = 1 ;
1421
1434
}
1422
1435
}
1423
1436
}
@@ -1485,18 +1498,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1485
1498
None
1486
1499
}
1487
1500
1488
- fn resolve_item_in_lexical_scope ( & mut self ,
1489
- name : Name ,
1490
- namespace : Namespace ,
1491
- record_used : bool )
1492
- -> ResolveResult < & ' a NameBinding < ' a > > {
1493
- let ident = hir:: Ident :: from_name ( name) ;
1494
- match self . resolve_ident_in_lexical_scope ( ident, namespace, record_used) {
1495
- Some ( LexicalScopeBinding :: Item ( binding) ) => Success ( binding) ,
1496
- _ => Failed ( None ) ,
1497
- }
1498
- }
1499
-
1500
1501
/// Returns the nearest normal module parent of the given module.
1501
1502
fn get_nearest_normal_module_parent ( & mut self , module_ : Module < ' a > ) -> Option < Module < ' a > > {
1502
1503
let mut module_ = module_;
@@ -2288,8 +2289,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2288
2289
let ident = path1. node ;
2289
2290
let renamed = ident. name ;
2290
2291
2291
- match self . resolve_bare_identifier_pattern ( ident. unhygienic_name ,
2292
- pattern. span ) {
2292
+ match self . resolve_bare_identifier_pattern ( ident, pattern. span ) {
2293
2293
FoundStructOrEnumVariant ( def) if const_ok => {
2294
2294
debug ! ( "(resolving pattern) resolving `{}` to struct or enum variant" ,
2295
2295
renamed) ;
@@ -2540,49 +2540,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2540
2540
} ) ;
2541
2541
}
2542
2542
2543
- fn resolve_bare_identifier_pattern ( & mut self ,
2544
- name : Name ,
2545
- span : Span )
2543
+ fn resolve_bare_identifier_pattern ( & mut self , ident : hir:: Ident , span : Span )
2546
2544
-> BareIdentifierPatternResolution {
2547
- match self . resolve_item_in_lexical_scope ( name, ValueNS , true ) {
2548
- Success ( binding) => {
2549
- debug ! ( "(resolve bare identifier pattern) succeeded in finding {} at {:?}" ,
2550
- name,
2551
- binding) ;
2552
- match binding. def ( ) {
2553
- None => {
2554
- panic ! ( "resolved name in the value namespace to a set of name bindings \
2555
- with no def?!") ;
2556
- }
2557
- // For the two success cases, this lookup can be
2558
- // considered as not having a private component because
2559
- // the lookup happened only within the current module.
2560
- Some ( def @ Def :: Variant ( ..) ) | Some ( def @ Def :: Struct ( ..) ) => {
2561
- return FoundStructOrEnumVariant ( def) ;
2562
- }
2563
- Some ( def @ Def :: Const ( ..) ) | Some ( def @ Def :: AssociatedConst ( ..) ) => {
2564
- return FoundConst ( def, name) ;
2565
- }
2566
- Some ( Def :: Static ( ..) ) => {
2567
- resolve_error ( self , span, ResolutionError :: StaticVariableReference ) ;
2568
- return BareIdentifierPatternUnresolved ;
2569
- }
2570
- _ => return BareIdentifierPatternUnresolved
2571
- }
2545
+ match self . resolve_ident_in_lexical_scope ( ident, ValueNS , true )
2546
+ . map ( LexicalScopeBinding :: def) {
2547
+ Some ( def @ Def :: Variant ( ..) ) | Some ( def @ Def :: Struct ( ..) ) => {
2548
+ FoundStructOrEnumVariant ( def)
2572
2549
}
2573
-
2574
- Indeterminate => return BareIdentifierPatternUnresolved ,
2575
- Failed ( err) => {
2576
- match err {
2577
- Some ( ( span, msg) ) => {
2578
- resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
2579
- }
2580
- None => ( ) ,
2581
- }
2582
-
2583
- debug ! ( "(resolve bare identifier pattern) failed to find {}" , name) ;
2584
- return BareIdentifierPatternUnresolved ;
2550
+ Some ( def @ Def :: Const ( ..) ) | Some ( def @ Def :: AssociatedConst ( ..) ) => {
2551
+ FoundConst ( def, ident. unhygienic_name )
2585
2552
}
2553
+ Some ( Def :: Static ( ..) ) => {
2554
+ resolve_error ( self , span, ResolutionError :: StaticVariableReference ) ;
2555
+ BareIdentifierPatternUnresolved
2556
+ }
2557
+ _ => BareIdentifierPatternUnresolved ,
2586
2558
}
2587
2559
}
2588
2560
@@ -2703,7 +2675,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2703
2675
return Some ( LocalDef :: from_def ( Def :: Err ) ) ;
2704
2676
}
2705
2677
2706
- self . resolve_identifier_in_local_ribs ( identifier, namespace, record_used)
2678
+ self . resolve_ident_in_lexical_scope ( identifier, namespace, record_used)
2679
+ . map ( LexicalScopeBinding :: local_def)
2707
2680
}
2708
2681
2709
2682
// Resolve a local definition, potentially adjusting for closures.
@@ -2887,18 +2860,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2887
2860
} )
2888
2861
}
2889
2862
2890
- fn resolve_identifier_in_local_ribs ( & mut self ,
2891
- ident : hir:: Ident ,
2892
- namespace : Namespace ,
2893
- record_used : bool )
2894
- -> Option < LocalDef > {
2895
- Some ( match self . resolve_ident_in_lexical_scope ( ident, namespace, record_used) {
2896
- Some ( LexicalScopeBinding :: LocalDef ( local_def) ) => local_def,
2897
- Some ( LexicalScopeBinding :: Item ( binding) ) => LocalDef :: from_def ( binding. def ( ) . unwrap ( ) ) ,
2898
- None => return None ,
2899
- } )
2900
- }
2901
-
2902
2863
fn with_no_errors < T , F > ( & mut self , f : F ) -> T
2903
2864
where F : FnOnce ( & mut Resolver ) -> T
2904
2865
{
0 commit comments