@@ -43,7 +43,6 @@ use rustc_front::hir::{PathListIdent, PathListMod, StmtDecl};
43
43
use rustc_front:: hir:: { Variant , ViewPathGlob , ViewPathList , ViewPathSimple } ;
44
44
use rustc_front:: intravisit:: { self , Visitor } ;
45
45
46
- use std:: mem:: replace;
47
46
use std:: ops:: { Deref , DerefMut } ;
48
47
49
48
struct GraphBuilder < ' a , ' b : ' a , ' tcx : ' b > {
@@ -122,7 +121,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
122
121
}
123
122
124
123
/// 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;
126
126
let name = item. name ;
127
127
let sp = item. span ;
128
128
let is_public = item. vis == hir:: Public ;
@@ -242,7 +242,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
242
242
is_prelude) ;
243
243
}
244
244
}
245
- parent
246
245
}
247
246
248
247
ItemExternCrate ( _) => {
@@ -260,7 +259,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
260
259
261
260
self . build_reduced_graph_for_external_crate ( module) ;
262
261
}
263
- parent
264
262
}
265
263
266
264
ItemMod ( ..) => {
@@ -269,34 +267,30 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
269
267
let module = self . new_module ( parent_link, Some ( def) , false , is_public) ;
270
268
self . define ( parent, name, TypeNS , ( module, sp) ) ;
271
269
parent. module_children . borrow_mut ( ) . insert ( item. id , module) ;
272
- module
270
+ * parent_ref = module;
273
271
}
274
272
275
- ItemForeignMod ( ..) => parent ,
273
+ ItemForeignMod ( ..) => { }
276
274
277
275
// These items live in the value namespace.
278
276
ItemStatic ( _, m, _) => {
279
277
let mutbl = m == hir:: MutMutable ;
280
278
let def = Def :: Static ( self . ast_map . local_def_id ( item. id ) , mutbl) ;
281
279
self . define ( parent, name, ValueNS , ( def, sp, modifiers) ) ;
282
- parent
283
280
}
284
281
ItemConst ( _, _) => {
285
282
let def = Def :: Const ( self . ast_map . local_def_id ( item. id ) ) ;
286
283
self . define ( parent, name, ValueNS , ( def, sp, modifiers) ) ;
287
- parent
288
284
}
289
285
ItemFn ( _, _, _, _, _, _) => {
290
286
let def = Def :: Fn ( self . ast_map . local_def_id ( item. id ) ) ;
291
287
self . define ( parent, name, ValueNS , ( def, sp, modifiers) ) ;
292
- parent
293
288
}
294
289
295
290
// These items live in the type namespace.
296
291
ItemTy ( ..) => {
297
292
let def = Def :: TyAlias ( self . ast_map . local_def_id ( item. id ) ) ;
298
293
self . define ( parent, name, TypeNS , ( def, sp, modifiers) ) ;
299
- parent
300
294
}
301
295
302
296
ItemEnum ( ref enum_definition, _) => {
@@ -315,7 +309,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
315
309
self . build_reduced_graph_for_variant ( variant, item_def_id,
316
310
module, variant_modifiers) ;
317
311
}
318
- parent
319
312
}
320
313
321
314
// These items live in both the type and value namespaces.
@@ -338,12 +331,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
338
331
. collect ( ) ;
339
332
let item_def_id = self . ast_map . local_def_id ( item. id ) ;
340
333
self . structs . insert ( item_def_id, field_names) ;
341
-
342
- parent
343
334
}
344
335
345
- ItemDefaultImpl ( _, _) |
346
- ItemImpl ( ..) => parent,
336
+ ItemDefaultImpl ( _, _) | ItemImpl ( ..) => { }
347
337
348
338
ItemTrait ( _, _, _, ref items) => {
349
339
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> {
368
358
369
359
self . trait_item_map . insert ( ( item. name , def_id) , item_def_id) ;
370
360
}
371
-
372
- parent
373
361
}
374
362
}
375
363
}
@@ -420,7 +408,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
420
408
self . define ( parent, name, ValueNS , ( def, foreign_item. span , modifiers) ) ;
421
409
}
422
410
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 > ) {
424
412
if self . block_needs_anonymous_module ( block) {
425
413
let block_id = block. id ;
426
414
@@ -431,9 +419,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
431
419
let parent_link = BlockParentLink ( parent, block_id) ;
432
420
let new_module = self . new_module ( parent_link, None , false , false ) ;
433
421
parent. module_children . borrow_mut ( ) . insert ( block_id, new_module) ;
434
- new_module
435
- } else {
436
- parent
422
+ * parent = new_module;
437
423
}
438
424
}
439
425
@@ -610,8 +596,8 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
610
596
}
611
597
612
598
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 ) ;
615
601
intravisit:: walk_item ( self , item) ;
616
602
self . parent = old_parent;
617
603
}
@@ -621,8 +607,8 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
621
607
}
622
608
623
609
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 ) ;
626
612
intravisit:: walk_block ( self , block) ;
627
613
self . parent = old_parent;
628
614
}
0 commit comments