@@ -56,12 +56,7 @@ impl<'b> Resolver<'b> {
56
56
pub fn build_reduced_graph ( & mut self , krate : & Crate ) {
57
57
let no_implicit_prelude = attr:: contains_name ( & krate. attrs , "no_implicit_prelude" ) ;
58
58
self . graph_root . no_implicit_prelude . set ( no_implicit_prelude) ;
59
-
60
- let mut visitor = BuildReducedGraphVisitor {
61
- parent : self . graph_root ,
62
- resolver : self ,
63
- } ;
64
- visit:: walk_crate ( & mut visitor, krate) ;
59
+ visit:: walk_crate ( & mut BuildReducedGraphVisitor { resolver : self } , krate) ;
65
60
}
66
61
67
62
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
@@ -84,11 +79,10 @@ impl<'b> Resolver<'b> {
84
79
}
85
80
86
81
/// Constructs the reduced graph for one item.
87
- fn build_reduced_graph_for_item ( & mut self , item : & Item , parent_ref : & mut Module < ' b > ) {
88
- let parent = * parent_ref ;
82
+ fn build_reduced_graph_for_item ( & mut self , item : & Item ) {
83
+ let parent = self . current_module ;
89
84
let name = item. ident . name ;
90
85
let sp = item. span ;
91
- self . current_module = parent;
92
86
let vis = self . resolve_visibility ( & item. vis ) ;
93
87
94
88
match item. node {
@@ -213,7 +207,7 @@ impl<'b> Resolver<'b> {
213
207
} ) ;
214
208
self . define ( parent, name, TypeNS , ( module, sp, vis) ) ;
215
209
self . module_map . insert ( item. id , module) ;
216
- * parent_ref = module;
210
+ self . current_module = module; // Descend into the module.
217
211
}
218
212
219
213
ItemKind :: ForeignMod ( ..) => { }
@@ -306,6 +300,9 @@ impl<'b> Resolver<'b> {
306
300
}
307
301
ItemKind :: Mac ( _) => panic ! ( "unexpanded macro in resolve!" ) ,
308
302
}
303
+
304
+ visit:: walk_item ( & mut BuildReducedGraphVisitor { resolver : self } , item) ;
305
+ self . current_module = parent;
309
306
}
310
307
311
308
// Constructs the reduced graph for one variant. Variants exist in the
@@ -330,9 +327,8 @@ impl<'b> Resolver<'b> {
330
327
}
331
328
332
329
/// Constructs the reduced graph for one foreign item.
333
- fn build_reduced_graph_for_foreign_item ( & mut self ,
334
- foreign_item : & ForeignItem ,
335
- parent : Module < ' b > ) {
330
+ fn build_reduced_graph_for_foreign_item ( & mut self , foreign_item : & ForeignItem ) {
331
+ let parent = self . current_module ;
336
332
let name = foreign_item. ident . name ;
337
333
338
334
let def = match foreign_item. node {
@@ -343,12 +339,12 @@ impl<'b> Resolver<'b> {
343
339
Def :: Static ( self . definitions . local_def_id ( foreign_item. id ) , m)
344
340
}
345
341
} ;
346
- self . current_module = parent;
347
342
let vis = self . resolve_visibility ( & foreign_item. vis ) ;
348
343
self . define ( parent, name, ValueNS , ( def, foreign_item. span , vis) ) ;
349
344
}
350
345
351
- fn build_reduced_graph_for_block ( & mut self , block : & Block , parent : & mut Module < ' b > ) {
346
+ fn build_reduced_graph_for_block ( & mut self , block : & Block ) {
347
+ let parent = self . current_module ;
352
348
if self . block_needs_anonymous_module ( block) {
353
349
let block_id = block. id ;
354
350
@@ -359,8 +355,11 @@ impl<'b> Resolver<'b> {
359
355
let parent_link = BlockParentLink ( parent, block_id) ;
360
356
let new_module = self . new_module ( parent_link, None , false ) ;
361
357
self . module_map . insert ( block_id, new_module) ;
362
- * parent = new_module;
358
+ self . current_module = new_module; // Descend into the block.
363
359
}
360
+
361
+ visit:: walk_block ( & mut BuildReducedGraphVisitor { resolver : self } , block) ;
362
+ self . current_module = parent;
364
363
}
365
364
366
365
/// Builds the reduced graph for a single item in an external crate.
@@ -484,25 +483,18 @@ impl<'b> Resolver<'b> {
484
483
485
484
struct BuildReducedGraphVisitor < ' a , ' b : ' a > {
486
485
resolver : & ' a mut Resolver < ' b > ,
487
- parent : Module < ' b > ,
488
486
}
489
487
490
488
impl < ' a , ' b > Visitor for BuildReducedGraphVisitor < ' a , ' b > {
491
489
fn visit_item ( & mut self , item : & Item ) {
492
- let old_parent = self . parent ;
493
- self . resolver . build_reduced_graph_for_item ( item, & mut self . parent ) ;
494
- visit:: walk_item ( self , item) ;
495
- self . parent = old_parent;
490
+ self . resolver . build_reduced_graph_for_item ( item) ;
496
491
}
497
492
498
493
fn visit_foreign_item ( & mut self , foreign_item : & ForeignItem ) {
499
- self . resolver . build_reduced_graph_for_foreign_item ( foreign_item, & self . parent ) ;
494
+ self . resolver . build_reduced_graph_for_foreign_item ( foreign_item) ;
500
495
}
501
496
502
497
fn visit_block ( & mut self , block : & Block ) {
503
- let old_parent = self . parent ;
504
- self . resolver . build_reduced_graph_for_block ( block, & mut self . parent ) ;
505
- visit:: walk_block ( self , block) ;
506
- self . parent = old_parent;
498
+ self . resolver . build_reduced_graph_for_block ( block) ;
507
499
}
508
500
}
0 commit comments