@@ -97,17 +97,6 @@ mod check_unused;
97
97
mod build_reduced_graph;
98
98
mod resolve_imports;
99
99
100
- // Perform the callback, not walking deeper if the return is true
101
- macro_rules! execute_callback {
102
- ( $node: expr, $walker: expr) => (
103
- if let Some ( ref callback) = $walker. callback {
104
- if callback( $node, & mut $walker. resolved) {
105
- return ;
106
- }
107
- }
108
- )
109
- }
110
-
111
100
enum SuggestionType {
112
101
Macro ( String ) ,
113
102
Function ( token:: InternedString ) ,
@@ -559,22 +548,18 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
559
548
self . visit_item ( self . ast_map . expect_item ( item. id ) )
560
549
}
561
550
fn visit_item ( & mut self , item : & Item ) {
562
- execute_callback ! ( hir_map:: Node :: NodeItem ( item) , self ) ;
563
551
self . resolve_item ( item) ;
564
552
}
565
553
fn visit_arm ( & mut self , arm : & Arm ) {
566
554
self . resolve_arm ( arm) ;
567
555
}
568
556
fn visit_block ( & mut self , block : & Block ) {
569
- execute_callback ! ( hir_map:: Node :: NodeBlock ( block) , self ) ;
570
557
self . resolve_block ( block) ;
571
558
}
572
559
fn visit_expr ( & mut self , expr : & Expr ) {
573
- execute_callback ! ( hir_map:: Node :: NodeExpr ( expr) , self ) ;
574
560
self . resolve_expr ( expr) ;
575
561
}
576
562
fn visit_local ( & mut self , local : & Local ) {
577
- execute_callback ! ( hir_map:: Node :: NodeLocal ( & local. pat) , self ) ;
578
563
self . resolve_local ( local) ;
579
564
}
580
565
fn visit_ty ( & mut self , ty : & Ty ) {
@@ -597,7 +582,6 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
597
582
variant : & hir:: Variant ,
598
583
generics : & Generics ,
599
584
item_id : ast:: NodeId ) {
600
- execute_callback ! ( hir_map:: Node :: NodeVariant ( variant) , self ) ;
601
585
if let Some ( ref dis_expr) = variant. node . disr_expr {
602
586
// resolve the discriminator expr as a constant
603
587
self . with_constant_rib ( |this| {
@@ -613,7 +597,6 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
613
597
variant. span ) ;
614
598
}
615
599
fn visit_foreign_item ( & mut self , foreign_item : & hir:: ForeignItem ) {
616
- execute_callback ! ( hir_map:: Node :: NodeForeignItem ( foreign_item) , self ) ;
617
600
let type_parameters = match foreign_item. node {
618
601
ForeignItemFn ( _, ref generics) => {
619
602
HasTypeParameters ( generics, FnSpace , ItemRibKind )
@@ -1080,11 +1063,6 @@ pub struct Resolver<'a, 'tcx: 'a> {
1080
1063
used_imports : HashSet < ( NodeId , Namespace ) > ,
1081
1064
used_crates : HashSet < CrateNum > ,
1082
1065
1083
- // Callback function for intercepting walks
1084
- callback : Option < Box < Fn ( hir_map:: Node , & mut bool ) -> bool > > ,
1085
- // The intention is that the callback modifies this flag.
1086
- // Once set, the resolver falls out of the walk, preserving the ribs.
1087
- resolved : bool ,
1088
1066
privacy_errors : Vec < PrivacyError < ' a > > ,
1089
1067
1090
1068
arenas : & ' a ResolverArenas < ' a > ,
@@ -1186,8 +1164,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1186
1164
make_glob_map : make_glob_map == MakeGlobMap :: Yes ,
1187
1165
glob_map : NodeMap ( ) ,
1188
1166
1189
- callback : None ,
1190
- resolved : false ,
1191
1167
privacy_errors : Vec :: new ( ) ,
1192
1168
1193
1169
arenas : arenas,
@@ -1758,13 +1734,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1758
1734
1759
1735
f ( self ) ;
1760
1736
1761
- match type_parameters {
1762
- HasTypeParameters ( ..) => {
1763
- if !self . resolved {
1764
- self . type_ribs . pop ( ) ;
1765
- }
1766
- }
1767
- NoTypeParameters => { }
1737
+ if let HasTypeParameters ( ..) = type_parameters {
1738
+ self . type_ribs . pop ( ) ;
1768
1739
}
1769
1740
}
1770
1741
@@ -1773,9 +1744,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1773
1744
{
1774
1745
self . label_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
1775
1746
f ( self ) ;
1776
- if !self . resolved {
1777
- self . label_ribs . pop ( ) ;
1778
- }
1747
+ self . label_ribs . pop ( ) ;
1779
1748
}
1780
1749
1781
1750
fn with_constant_rib < F > ( & mut self , f : F )
@@ -1784,10 +1753,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1784
1753
self . value_ribs . push ( Rib :: new ( ConstantItemRibKind ) ) ;
1785
1754
self . type_ribs . push ( Rib :: new ( ConstantItemRibKind ) ) ;
1786
1755
f ( self ) ;
1787
- if !self . resolved {
1788
- self . type_ribs . pop ( ) ;
1789
- self . value_ribs . pop ( ) ;
1790
- }
1756
+ self . type_ribs . pop ( ) ;
1757
+ self . value_ribs . pop ( ) ;
1791
1758
}
1792
1759
1793
1760
fn resolve_function ( & mut self , rib_kind : RibKind < ' a > , declaration : & FnDecl , block : & Block ) {
@@ -1813,10 +1780,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1813
1780
1814
1781
debug ! ( "(resolving function) leaving function" ) ;
1815
1782
1816
- if !self . resolved {
1817
- self . label_ribs . pop ( ) ;
1818
- self . value_ribs . pop ( ) ;
1819
- }
1783
+ self . label_ribs . pop ( ) ;
1784
+ self . value_ribs . pop ( ) ;
1820
1785
}
1821
1786
1822
1787
fn resolve_trait_reference ( & mut self ,
@@ -1950,9 +1915,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1950
1915
self_type_rib. bindings . insert ( keywords:: SelfType . name ( ) , self_def) ;
1951
1916
self . type_ribs . push ( self_type_rib) ;
1952
1917
f ( self ) ;
1953
- if !self . resolved {
1954
- self . type_ribs . pop ( ) ;
1955
- }
1918
+ self . type_ribs . pop ( ) ;
1956
1919
}
1957
1920
1958
1921
fn resolve_implementation ( & mut self ,
@@ -2117,9 +2080,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2117
2080
walk_list ! ( self , visit_expr, & arm. guard) ;
2118
2081
self . visit_expr ( & arm. body ) ;
2119
2082
2120
- if !self . resolved {
2121
- self . value_ribs . pop ( ) ;
2122
- }
2083
+ self . value_ribs . pop ( ) ;
2123
2084
}
2124
2085
2125
2086
fn resolve_block ( & mut self , block : & Block ) {
@@ -2141,12 +2102,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2141
2102
intravisit:: walk_block ( self , block) ;
2142
2103
2143
2104
// Move back up.
2144
- if !self . resolved {
2145
- self . current_module = orig_module;
2146
- self . value_ribs . pop ( ) ;
2147
- if let Some ( _) = anonymous_module {
2148
- self . type_ribs . pop ( ) ;
2149
- }
2105
+ self . current_module = orig_module;
2106
+ self . value_ribs . pop ( ) ;
2107
+ if let Some ( _) = anonymous_module {
2108
+ self . type_ribs . pop ( ) ;
2150
2109
}
2151
2110
debug ! ( "(resolving block) leaving block" ) ;
2152
2111
}
@@ -3588,7 +3547,7 @@ pub fn resolve_crate<'a, 'tcx>(session: &'a Session,
3588
3547
3589
3548
let krate = ast_map. krate ( ) ;
3590
3549
let arenas = Resolver :: arenas ( ) ;
3591
- let mut resolver = create_resolver ( session, ast_map, krate, make_glob_map, & arenas, None ) ;
3550
+ let mut resolver = create_resolver ( session, ast_map, krate, make_glob_map, & arenas) ;
3592
3551
3593
3552
resolver. resolve_crate ( krate) ;
3594
3553
@@ -3608,25 +3567,15 @@ pub fn resolve_crate<'a, 'tcx>(session: &'a Session,
3608
3567
}
3609
3568
}
3610
3569
3611
- /// Builds a name resolution walker to be used within this module,
3612
- /// or used externally, with an optional callback function.
3613
- ///
3614
- /// The callback takes a &mut bool which allows callbacks to end a
3615
- /// walk when set to true, passing through the rest of the walk, while
3616
- /// preserving the ribs + current module. This allows resolve_path
3617
- /// calls to be made with the correct scope info. The node in the
3618
- /// callback corresponds to the current node in the walk.
3570
+ /// Builds a name resolution walker.
3619
3571
fn create_resolver < ' a , ' tcx > ( session : & ' a Session ,
3620
3572
ast_map : & ' a hir_map:: Map < ' tcx > ,
3621
3573
krate : & ' a Crate ,
3622
3574
make_glob_map : MakeGlobMap ,
3623
- arenas : & ' a ResolverArenas < ' a > ,
3624
- callback : Option < Box < Fn ( hir_map:: Node , & mut bool ) -> bool > > )
3575
+ arenas : & ' a ResolverArenas < ' a > )
3625
3576
-> Resolver < ' a , ' tcx > {
3626
3577
let mut resolver = Resolver :: new ( session, ast_map, make_glob_map, arenas) ;
3627
3578
3628
- resolver. callback = callback;
3629
-
3630
3579
resolver. build_reduced_graph ( krate) ;
3631
3580
3632
3581
resolve_imports:: resolve_imports ( & mut resolver) ;
0 commit comments