@@ -109,17 +109,6 @@ mod record_exports;
109
109
mod build_reduced_graph;
110
110
mod resolve_imports;
111
111
112
- // Perform the callback, not walking deeper if the return is true
113
- macro_rules! execute_callback {
114
- ( $node: expr, $walker: expr) => (
115
- if let Some ( ref callback) = $walker. callback {
116
- if callback( $node, & mut $walker. resolved) {
117
- return ;
118
- }
119
- }
120
- )
121
- }
122
-
123
112
pub enum ResolutionError < ' a > {
124
113
/// error E0401: can't use type parameters from outer function
125
114
TypeParametersFromOuterFunction ,
@@ -408,7 +397,7 @@ enum PatternBindingMode {
408
397
}
409
398
410
399
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
411
- pub enum Namespace {
400
+ enum Namespace {
412
401
TypeNS ,
413
402
ValueNS
414
403
}
@@ -456,22 +445,18 @@ enum NameDefinition {
456
445
457
446
impl < ' a , ' v , ' tcx > Visitor < ' v > for Resolver < ' a , ' tcx > {
458
447
fn visit_item ( & mut self , item : & Item ) {
459
- execute_callback ! ( ast_map:: Node :: NodeItem ( item) , self ) ;
460
448
self . resolve_item ( item) ;
461
449
}
462
450
fn visit_arm ( & mut self , arm : & Arm ) {
463
451
self . resolve_arm ( arm) ;
464
452
}
465
453
fn visit_block ( & mut self , block : & Block ) {
466
- execute_callback ! ( ast_map:: Node :: NodeBlock ( block) , self ) ;
467
454
self . resolve_block ( block) ;
468
455
}
469
456
fn visit_expr ( & mut self , expr : & Expr ) {
470
- execute_callback ! ( ast_map:: Node :: NodeExpr ( expr) , self ) ;
471
457
self . resolve_expr ( expr) ;
472
458
}
473
459
fn visit_local ( & mut self , local : & Local ) {
474
- execute_callback ! ( ast_map:: Node :: NodeLocal ( & * local. pat) , self ) ;
475
460
self . resolve_local ( local) ;
476
461
}
477
462
fn visit_ty ( & mut self , ty : & Ty ) {
@@ -490,7 +475,6 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
490
475
visit:: walk_poly_trait_ref ( self , tref, m) ;
491
476
}
492
477
fn visit_variant ( & mut self , variant : & ast:: Variant , generics : & Generics ) {
493
- execute_callback ! ( ast_map:: Node :: NodeVariant ( variant) , self ) ;
494
478
if let Some ( ref dis_expr) = variant. node . disr_expr {
495
479
// resolve the discriminator expr as a constant
496
480
self . with_constant_rib ( |this| {
@@ -514,7 +498,6 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
514
498
}
515
499
}
516
500
fn visit_foreign_item ( & mut self , foreign_item : & ast:: ForeignItem ) {
517
- execute_callback ! ( ast_map:: Node :: NodeForeignItem ( foreign_item) , self ) ;
518
501
let type_parameters = match foreign_item. node {
519
502
ForeignItemFn ( _, ref generics) => {
520
503
HasTypeParameters ( generics, FnSpace , ItemRibKind )
@@ -1164,13 +1147,6 @@ pub struct Resolver<'a, 'tcx:'a> {
1164
1147
1165
1148
used_imports : HashSet < ( NodeId , Namespace ) > ,
1166
1149
used_crates : HashSet < CrateNum > ,
1167
-
1168
- // Callback function for intercepting walks
1169
- callback : Option < Box < Fn ( ast_map:: Node , & mut bool ) -> bool > > ,
1170
- // The intention is that the callback modifies this flag.
1171
- // Once set, the resolver falls out of the walk, preserving the ribs.
1172
- resolved : bool ,
1173
-
1174
1150
}
1175
1151
1176
1152
#[ derive( PartialEq ) ]
@@ -1232,10 +1208,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1232
1208
emit_errors : true ,
1233
1209
make_glob_map : make_glob_map == MakeGlobMap :: Yes ,
1234
1210
glob_map : HashMap :: new ( ) ,
1235
-
1236
- callback : None ,
1237
- resolved : false ,
1238
-
1239
1211
}
1240
1212
}
1241
1213
@@ -2262,7 +2234,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2262
2234
f ( self ) ;
2263
2235
2264
2236
match type_parameters {
2265
- HasTypeParameters ( ..) => { if ! self . resolved { self . type_ribs . pop ( ) ; } }
2237
+ HasTypeParameters ( ..) => { self . type_ribs . pop ( ) ; }
2266
2238
NoTypeParameters => { }
2267
2239
}
2268
2240
}
@@ -2272,9 +2244,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2272
2244
{
2273
2245
self . label_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
2274
2246
f ( self ) ;
2275
- if !self . resolved {
2276
- self . label_ribs . pop ( ) ;
2277
- }
2247
+ self . label_ribs . pop ( ) ;
2278
2248
}
2279
2249
2280
2250
fn with_constant_rib < F > ( & mut self , f : F ) where
@@ -2283,10 +2253,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2283
2253
self . value_ribs . push ( Rib :: new ( ConstantItemRibKind ) ) ;
2284
2254
self . type_ribs . push ( Rib :: new ( ConstantItemRibKind ) ) ;
2285
2255
f ( self ) ;
2286
- if !self . resolved {
2287
- self . type_ribs . pop ( ) ;
2288
- self . value_ribs . pop ( ) ;
2289
- }
2256
+ self . type_ribs . pop ( ) ;
2257
+ self . value_ribs . pop ( ) ;
2290
2258
}
2291
2259
2292
2260
fn resolve_function ( & mut self ,
@@ -2317,10 +2285,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2317
2285
2318
2286
debug ! ( "(resolving function) leaving function" ) ;
2319
2287
2320
- if !self . resolved {
2321
- self . label_ribs . pop ( ) ;
2322
- self . value_ribs . pop ( ) ;
2323
- }
2288
+ self . label_ribs . pop ( ) ;
2289
+ self . value_ribs . pop ( ) ;
2324
2290
}
2325
2291
2326
2292
fn resolve_trait_reference ( & mut self ,
@@ -2423,9 +2389,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2423
2389
self_type_rib. bindings . insert ( name, DlDef ( self_def) ) ;
2424
2390
self . type_ribs . push ( self_type_rib) ;
2425
2391
f ( self ) ;
2426
- if !self . resolved {
2427
- self . type_ribs . pop ( ) ;
2428
- }
2392
+ self . type_ribs . pop ( ) ;
2429
2393
}
2430
2394
2431
2395
fn resolve_implementation ( & mut self ,
@@ -2594,9 +2558,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2594
2558
visit:: walk_expr_opt ( self , & arm. guard ) ;
2595
2559
self . visit_expr ( & * arm. body ) ;
2596
2560
2597
- if !self . resolved {
2598
- self . value_ribs . pop ( ) ;
2599
- }
2561
+ self . value_ribs . pop ( ) ;
2600
2562
}
2601
2563
2602
2564
fn resolve_block ( & mut self , block : & Block ) {
@@ -2638,10 +2600,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2638
2600
visit:: walk_block ( self , block) ;
2639
2601
2640
2602
// Move back up.
2641
- if !self . resolved {
2642
- self . current_module = orig_module;
2643
- self . value_ribs . pop ( ) ;
2644
- }
2603
+ self . current_module = orig_module;
2604
+
2605
+ self . value_ribs . pop ( ) ;
2645
2606
debug ! ( "(resolving block) leaving block" ) ;
2646
2607
}
2647
2608
@@ -3083,12 +3044,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3083
3044
/// doesn't skip straight to the containing module.
3084
3045
/// Skips `path_depth` trailing segments, which is also reflected in the
3085
3046
/// returned value. See `middle::def::PathResolution` for more info.
3086
- pub fn resolve_path ( & mut self ,
3087
- id : NodeId ,
3088
- path : & Path ,
3089
- path_depth : usize ,
3090
- namespace : Namespace ,
3091
- check_ribs : bool ) -> Option < PathResolution > {
3047
+ fn resolve_path ( & mut self ,
3048
+ id : NodeId ,
3049
+ path : & Path ,
3050
+ path_depth : usize ,
3051
+ namespace : Namespace ,
3052
+ check_ribs : bool ) -> Option < PathResolution > {
3092
3053
let span = path. span ;
3093
3054
let segments = & path. segments [ ..path. segments . len ( ) -path_depth] ;
3094
3055
@@ -4027,7 +3988,16 @@ pub fn resolve_crate<'a, 'tcx>(session: &'a Session,
4027
3988
make_glob_map : MakeGlobMap )
4028
3989
-> CrateMap {
4029
3990
let krate = ast_map. krate ( ) ;
4030
- let mut resolver = create_resolver ( session, ast_map, krate, make_glob_map, None ) ;
3991
+ let mut resolver = Resolver :: new ( session, ast_map, krate. span , make_glob_map) ;
3992
+
3993
+ build_reduced_graph:: build_reduced_graph ( & mut resolver, krate) ;
3994
+ session. abort_if_errors ( ) ;
3995
+
3996
+ resolve_imports:: resolve_imports ( & mut resolver) ;
3997
+ session. abort_if_errors ( ) ;
3998
+
3999
+ record_exports:: record ( & mut resolver) ;
4000
+ session. abort_if_errors ( ) ;
4031
4001
4032
4002
resolver. resolve_crate ( krate) ;
4033
4003
session. abort_if_errors ( ) ;
@@ -4048,34 +4018,4 @@ pub fn resolve_crate<'a, 'tcx>(session: &'a Session,
4048
4018
}
4049
4019
}
4050
4020
4051
- /// Builds a name resolution walker to be used within this module,
4052
- /// or used externally, with an optional callback function.
4053
- ///
4054
- /// The callback takes a &mut bool which allows callbacks to end a
4055
- /// walk when set to true, passing through the rest of the walk, while
4056
- /// preserving the ribs + current module. This allows resolve_path
4057
- /// calls to be made with the correct scope info. The node in the
4058
- /// callback corresponds to the current node in the walk.
4059
- pub fn create_resolver < ' a , ' tcx > ( session : & ' a Session ,
4060
- ast_map : & ' a ast_map:: Map < ' tcx > ,
4061
- krate : & ' a Crate ,
4062
- make_glob_map : MakeGlobMap ,
4063
- callback : Option < Box < Fn ( ast_map:: Node , & mut bool ) -> bool > > )
4064
- -> Resolver < ' a , ' tcx > {
4065
- let mut resolver = Resolver :: new ( session, ast_map, krate. span , make_glob_map) ;
4066
-
4067
- resolver. callback = callback;
4068
-
4069
- build_reduced_graph:: build_reduced_graph ( & mut resolver, krate) ;
4070
- session. abort_if_errors ( ) ;
4071
-
4072
- resolve_imports:: resolve_imports ( & mut resolver) ;
4073
- session. abort_if_errors ( ) ;
4074
-
4075
- record_exports:: record ( & mut resolver) ;
4076
- session. abort_if_errors ( ) ;
4077
-
4078
- resolver
4079
- }
4080
-
4081
4021
__build_diagnostic_array ! { librustc_resolve, DIAGNOSTICS }
0 commit comments