@@ -43,7 +43,6 @@ use rustc_front::hir::{PathListIdent, PathListMod, StmtDecl};
4343use rustc_front:: hir:: { Variant , ViewPathGlob , ViewPathList , ViewPathSimple } ;
4444use rustc_front:: intravisit:: { self , Visitor } ;
4545
46- use std:: mem:: replace;
4746use std:: ops:: { Deref , DerefMut } ;
4847
4948struct GraphBuilder < ' a , ' b : ' a , ' tcx : ' b > {
@@ -122,7 +121,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
122121 }
123122
124123 /// Constructs the reduced graph for one item.
125- fn build_reduced_graph_for_item ( & mut self , item : & Item , parent : Module < ' b > ) -> Module < ' b > {
124+ fn build_reduced_graph_for_item ( & mut self , item : & Item , parent_ref : & mut Module < ' b > ) {
125+ let parent = * parent_ref;
126126 let name = item. name ;
127127 let sp = item. span ;
128128 let is_public = item. vis == hir:: Public ;
@@ -242,7 +242,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
242242 is_prelude) ;
243243 }
244244 }
245- parent
246245 }
247246
248247 ItemExternCrate ( _) => {
@@ -260,7 +259,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
260259
261260 self . build_reduced_graph_for_external_crate ( module) ;
262261 }
263- parent
264262 }
265263
266264 ItemMod ( ..) => {
@@ -269,34 +267,30 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
269267 let module = self . new_module ( parent_link, Some ( def) , false , is_public) ;
270268 self . define ( parent, name, TypeNS , ( module, sp) ) ;
271269 parent. module_children . borrow_mut ( ) . insert ( item. id , module) ;
272- module
270+ * parent_ref = module;
273271 }
274272
275- ItemForeignMod ( ..) => parent ,
273+ ItemForeignMod ( ..) => { }
276274
277275 // These items live in the value namespace.
278276 ItemStatic ( _, m, _) => {
279277 let mutbl = m == hir:: MutMutable ;
280278 let def = Def :: Static ( self . ast_map . local_def_id ( item. id ) , mutbl) ;
281279 self . define ( parent, name, ValueNS , ( def, sp, modifiers) ) ;
282- parent
283280 }
284281 ItemConst ( _, _) => {
285282 let def = Def :: Const ( self . ast_map . local_def_id ( item. id ) ) ;
286283 self . define ( parent, name, ValueNS , ( def, sp, modifiers) ) ;
287- parent
288284 }
289285 ItemFn ( _, _, _, _, _, _) => {
290286 let def = Def :: Fn ( self . ast_map . local_def_id ( item. id ) ) ;
291287 self . define ( parent, name, ValueNS , ( def, sp, modifiers) ) ;
292- parent
293288 }
294289
295290 // These items live in the type namespace.
296291 ItemTy ( ..) => {
297292 let def = Def :: TyAlias ( self . ast_map . local_def_id ( item. id ) ) ;
298293 self . define ( parent, name, TypeNS , ( def, sp, modifiers) ) ;
299- parent
300294 }
301295
302296 ItemEnum ( ref enum_definition, _) => {
@@ -315,7 +309,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
315309 self . build_reduced_graph_for_variant ( variant, item_def_id,
316310 module, variant_modifiers) ;
317311 }
318- parent
319312 }
320313
321314 // These items live in both the type and value namespaces.
@@ -338,12 +331,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
338331 . collect ( ) ;
339332 let item_def_id = self . ast_map . local_def_id ( item. id ) ;
340333 self . structs . insert ( item_def_id, field_names) ;
341-
342- parent
343334 }
344335
345- ItemDefaultImpl ( _, _) |
346- ItemImpl ( ..) => parent,
336+ ItemDefaultImpl ( _, _) | ItemImpl ( ..) => { }
347337
348338 ItemTrait ( _, _, _, ref items) => {
349339 let def_id = self . ast_map . local_def_id ( item. id ) ;
@@ -368,8 +358,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
368358
369359 self . trait_item_map . insert ( ( item. name , def_id) , item_def_id) ;
370360 }
371-
372- parent
373361 }
374362 }
375363 }
@@ -420,7 +408,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
420408 self . define ( parent, name, ValueNS , ( def, foreign_item. span , modifiers) ) ;
421409 }
422410
423- fn build_reduced_graph_for_block ( & mut self , block : & Block , parent : Module < ' b > ) -> Module < ' b > {
411+ fn build_reduced_graph_for_block ( & mut self , block : & Block , parent : & mut Module < ' b > ) {
424412 if self . block_needs_anonymous_module ( block) {
425413 let block_id = block. id ;
426414
@@ -431,9 +419,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
431419 let parent_link = BlockParentLink ( parent, block_id) ;
432420 let new_module = self . new_module ( parent_link, None , false , false ) ;
433421 parent. module_children . borrow_mut ( ) . insert ( block_id, new_module) ;
434- new_module
435- } else {
436- parent
422+ * parent = new_module;
437423 }
438424 }
439425
@@ -610,8 +596,8 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
610596 }
611597
612598 fn visit_item ( & mut self , item : & Item ) {
613- let p = self . builder . build_reduced_graph_for_item ( item , & self . parent ) ;
614- let old_parent = replace ( & mut self . parent , p ) ;
599+ let old_parent = self . parent ;
600+ self . builder . build_reduced_graph_for_item ( item , & mut self . parent ) ;
615601 intravisit:: walk_item ( self , item) ;
616602 self . parent = old_parent;
617603 }
@@ -621,8 +607,8 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
621607 }
622608
623609 fn visit_block ( & mut self , block : & Block ) {
624- let np = self . builder . build_reduced_graph_for_block ( block , & self . parent ) ;
625- let old_parent = replace ( & mut self . parent , np ) ;
610+ let old_parent = self . parent ;
611+ self . builder . build_reduced_graph_for_block ( block , & mut self . parent ) ;
626612 intravisit:: walk_block ( self , block) ;
627613 self . parent = old_parent;
628614 }
0 commit comments