@@ -21,7 +21,7 @@ use Module;
21
21
use Namespace :: { TypeNS , ValueNS } ;
22
22
use NameBindings ;
23
23
use { names_to_string, module_to_string} ;
24
- use ParentLink :: { self , ModuleParentLink , BlockParentLink } ;
24
+ use ParentLink :: { ModuleParentLink , BlockParentLink } ;
25
25
use Resolver ;
26
26
use resolve_imports:: Shadowable ;
27
27
use { resolve_error, resolve_struct_error, ResolutionError } ;
@@ -52,7 +52,6 @@ use rustc_front::intravisit::{self, Visitor};
52
52
53
53
use std:: mem:: replace;
54
54
use std:: ops:: { Deref , DerefMut } ;
55
- use std:: rc:: Rc ;
56
55
57
56
// Specifies how duplicates should be handled when adding a child item if
58
57
// another item exists with the same name in some namespace.
@@ -86,7 +85,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
86
85
/// Constructs the reduced graph for the entire crate.
87
86
fn build_reduced_graph ( self , krate : & hir:: Crate ) {
88
87
let mut visitor = BuildReducedGraphVisitor {
89
- parent : self . graph_root . clone ( ) ,
88
+ parent : self . graph_root ,
90
89
builder : self ,
91
90
} ;
92
91
intravisit:: walk_crate ( & mut visitor, krate) ;
@@ -97,12 +96,12 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
97
96
/// Returns the child's corresponding name bindings.
98
97
fn add_child ( & self ,
99
98
name : Name ,
100
- parent : & Rc < Module > ,
99
+ parent : Module < ' b > ,
101
100
duplicate_checking_mode : DuplicateCheckingMode ,
102
101
// For printing errors
103
102
sp : Span )
104
- -> NameBindings {
105
- self . check_for_conflicts_between_external_crates_and_items ( & * * parent, name, sp) ;
103
+ -> NameBindings < ' b > {
104
+ self . check_for_conflicts_between_external_crates_and_items ( parent, name, sp) ;
106
105
107
106
// Add or reuse the child.
108
107
let child = parent. children . borrow ( ) . get ( & name) . cloned ( ) ;
@@ -178,12 +177,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
178
177
return false ;
179
178
}
180
179
181
- fn get_parent_link ( & mut self , parent : & Rc < Module > , name : Name ) -> ParentLink {
182
- ModuleParentLink ( Rc :: downgrade ( parent) , name)
183
- }
184
-
185
180
/// Constructs the reduced graph for one item.
186
- fn build_reduced_graph_for_item ( & mut self , item : & Item , parent : & Rc < Module > ) -> Rc < Module > {
181
+ fn build_reduced_graph_for_item ( & mut self , item : & Item , parent : Module < ' b > ) -> Module < ' b > {
187
182
let name = item. name ;
188
183
let sp = item. span ;
189
184
let is_public = item. vis == hir:: Public ;
@@ -238,7 +233,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
238
233
}
239
234
240
235
let subclass = SingleImport ( binding, source_name) ;
241
- self . build_import_directive ( & * * parent,
236
+ self . build_import_directive ( parent,
242
237
module_path,
243
238
subclass,
244
239
view_path. span ,
@@ -288,7 +283,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
288
283
( module_path. to_vec ( ) , name, rename)
289
284
}
290
285
} ;
291
- self . build_import_directive ( & * * parent,
286
+ self . build_import_directive ( parent,
292
287
module_path,
293
288
SingleImport ( rename, name) ,
294
289
source_item. span ,
@@ -298,7 +293,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
298
293
}
299
294
}
300
295
ViewPathGlob ( _) => {
301
- self . build_import_directive ( & * * parent,
296
+ self . build_import_directive ( parent,
302
297
module_path,
303
298
GlobImport ,
304
299
view_path. span ,
@@ -307,7 +302,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
307
302
shadowable) ;
308
303
}
309
304
}
310
- parent. clone ( )
305
+ parent
311
306
}
312
307
313
308
ItemExternCrate ( _) => {
@@ -319,32 +314,32 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
319
314
index : CRATE_DEF_INDEX ,
320
315
} ;
321
316
self . external_exports . insert ( def_id) ;
322
- let parent_link = ModuleParentLink ( Rc :: downgrade ( parent) , name) ;
317
+ let parent_link = ModuleParentLink ( parent, name) ;
323
318
let def = DefMod ( def_id) ;
324
- let external_module = Module :: new ( parent_link, Some ( def) , false , true ) ;
319
+ let external_module = self . new_module ( parent_link, Some ( def) , false , true ) ;
325
320
326
321
debug ! ( "(build reduced graph for item) found extern `{}`" ,
327
322
module_to_string( & * external_module) ) ;
328
- self . check_for_conflicts_for_external_crate ( & parent, name, sp) ;
323
+ self . check_for_conflicts_for_external_crate ( parent, name, sp) ;
329
324
parent. external_module_children
330
325
. borrow_mut ( )
331
- . insert ( name, external_module. clone ( ) ) ;
326
+ . insert ( name, external_module) ;
332
327
self . build_reduced_graph_for_external_crate ( & external_module) ;
333
328
}
334
- parent. clone ( )
329
+ parent
335
330
}
336
331
337
332
ItemMod ( ..) => {
338
333
let name_bindings = self . add_child ( name, parent, ForbidDuplicateTypes , sp) ;
339
334
340
- let parent_link = self . get_parent_link ( parent, name) ;
335
+ let parent_link = ModuleParentLink ( parent, name) ;
341
336
let def = DefMod ( self . ast_map . local_def_id ( item. id ) ) ;
342
- let module = Module :: new ( parent_link, Some ( def) , false , is_public) ;
337
+ let module = self . new_module ( parent_link, Some ( def) , false , is_public) ;
343
338
name_bindings. define_module ( module. clone ( ) , sp) ;
344
339
module
345
340
}
346
341
347
- ItemForeignMod ( ..) => parent. clone ( ) ,
342
+ ItemForeignMod ( ..) => parent,
348
343
349
344
// These items live in the value namespace.
350
345
ItemStatic ( _, m, _) => {
@@ -354,19 +349,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
354
349
name_bindings. define_value ( DefStatic ( self . ast_map . local_def_id ( item. id ) , mutbl) ,
355
350
sp,
356
351
modifiers) ;
357
- parent. clone ( )
352
+ parent
358
353
}
359
354
ItemConst ( _, _) => {
360
355
self . add_child ( name, parent, ForbidDuplicateValues , sp)
361
356
. define_value ( DefConst ( self . ast_map . local_def_id ( item. id ) ) , sp, modifiers) ;
362
- parent. clone ( )
357
+ parent
363
358
}
364
359
ItemFn ( _, _, _, _, _, _) => {
365
360
let name_bindings = self . add_child ( name, parent, ForbidDuplicateValues , sp) ;
366
361
367
362
let def = DefFn ( self . ast_map . local_def_id ( item. id ) , false ) ;
368
363
name_bindings. define_value ( def, sp, modifiers) ;
369
- parent. clone ( )
364
+ parent
370
365
}
371
366
372
367
// These items live in the type namespace.
@@ -376,11 +371,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
376
371
ForbidDuplicateTypes ,
377
372
sp) ;
378
373
379
- let parent_link = self . get_parent_link ( parent, name) ;
374
+ let parent_link = ModuleParentLink ( parent, name) ;
380
375
let def = DefTy ( self . ast_map . local_def_id ( item. id ) , false ) ;
381
- let module = Module :: new ( parent_link, Some ( def) , false , is_public) ;
376
+ let module = self . new_module ( parent_link, Some ( def) , false , is_public) ;
382
377
name_bindings. define_module ( module, sp) ;
383
- parent. clone ( )
378
+ parent
384
379
}
385
380
386
381
ItemEnum ( ref enum_definition, _) => {
@@ -389,9 +384,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
389
384
ForbidDuplicateTypes ,
390
385
sp) ;
391
386
392
- let parent_link = self . get_parent_link ( parent, name) ;
387
+ let parent_link = ModuleParentLink ( parent, name) ;
393
388
let def = DefTy ( self . ast_map . local_def_id ( item. id ) , true ) ;
394
- let module = Module :: new ( parent_link, Some ( def) , false , is_public) ;
389
+ let module = self . new_module ( parent_link, Some ( def) , false , is_public) ;
395
390
name_bindings. define_module ( module. clone ( ) , sp) ;
396
391
397
392
let variant_modifiers = if is_public {
@@ -404,7 +399,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
404
399
self . build_reduced_graph_for_variant ( variant, item_def_id,
405
400
& module, variant_modifiers) ;
406
401
}
407
- parent. clone ( )
402
+ parent
408
403
}
409
404
410
405
// These items live in both the type and value namespaces.
@@ -444,11 +439,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
444
439
let item_def_id = self . ast_map . local_def_id ( item. id ) ;
445
440
self . structs . insert ( item_def_id, named_fields) ;
446
441
447
- parent. clone ( )
442
+ parent
448
443
}
449
444
450
445
ItemDefaultImpl ( _, _) |
451
- ItemImpl ( ..) => parent. clone ( ) ,
446
+ ItemImpl ( ..) => parent,
452
447
453
448
ItemTrait ( _, _, _, ref items) => {
454
449
let name_bindings = self . add_child ( name,
@@ -459,9 +454,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
459
454
let def_id = self . ast_map . local_def_id ( item. id ) ;
460
455
461
456
// Add all the items within to a new module.
462
- let parent_link = self . get_parent_link ( parent, name) ;
457
+ let parent_link = ModuleParentLink ( parent, name) ;
463
458
let def = DefTrait ( def_id) ;
464
- let module_parent = Module :: new ( parent_link, Some ( def) , false , is_public) ;
459
+ let module_parent = self . new_module ( parent_link, Some ( def) , false , is_public) ;
465
460
name_bindings. define_module ( module_parent. clone ( ) , sp) ;
466
461
467
462
// Add the names of all the items to the trait info.
@@ -494,7 +489,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
494
489
self . trait_item_map . insert ( ( trait_item. name , def_id) , trait_item_def_id) ;
495
490
}
496
491
497
- parent. clone ( )
492
+ parent
498
493
}
499
494
}
500
495
}
@@ -504,7 +499,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
504
499
fn build_reduced_graph_for_variant ( & mut self ,
505
500
variant : & Variant ,
506
501
item_id : DefId ,
507
- parent : & Rc < Module > ,
502
+ parent : Module < ' b > ,
508
503
variant_modifiers : DefModifiers ) {
509
504
let name = variant. node . name ;
510
505
let is_exported = if variant. node . data . is_struct ( ) {
@@ -534,7 +529,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
534
529
/// Constructs the reduced graph for one foreign item.
535
530
fn build_reduced_graph_for_foreign_item ( & mut self ,
536
531
foreign_item : & ForeignItem ,
537
- parent : & Rc < Module > ) {
532
+ parent : Module < ' b > ) {
538
533
let name = foreign_item. name ;
539
534
let is_public = foreign_item. vis == hir:: Public ;
540
535
let modifiers = if is_public {
@@ -555,30 +550,30 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
555
550
name_bindings. define_value ( def, foreign_item. span , modifiers) ;
556
551
}
557
552
558
- fn build_reduced_graph_for_block ( & mut self , block : & Block , parent : & Rc < Module > ) -> Rc < Module > {
553
+ fn build_reduced_graph_for_block ( & mut self , block : & Block , parent : Module < ' b > ) -> Module < ' b > {
559
554
if self . block_needs_anonymous_module ( block) {
560
555
let block_id = block. id ;
561
556
562
557
debug ! ( "(building reduced graph for block) creating a new anonymous module for block \
563
558
{}",
564
559
block_id) ;
565
560
566
- let parent_link = BlockParentLink ( Rc :: downgrade ( parent) , block_id) ;
567
- let new_module = Module :: new ( parent_link, None , false , false ) ;
568
- parent. anonymous_children . borrow_mut ( ) . insert ( block_id, new_module. clone ( ) ) ;
561
+ let parent_link = BlockParentLink ( parent, block_id) ;
562
+ let new_module = self . new_module ( parent_link, None , false , false ) ;
563
+ parent. anonymous_children . borrow_mut ( ) . insert ( block_id, new_module) ;
569
564
new_module
570
565
} else {
571
- parent. clone ( )
566
+ parent
572
567
}
573
568
}
574
569
575
570
fn handle_external_def ( & mut self ,
576
571
def : Def ,
577
572
vis : Visibility ,
578
- child_name_bindings : & NameBindings ,
573
+ child_name_bindings : & NameBindings < ' b > ,
579
574
final_ident : & str ,
580
575
name : Name ,
581
- new_parent : & Rc < Module > ) {
576
+ new_parent : Module < ' b > ) {
582
577
debug ! ( "(building reduced graph for external crate) building external def {}, priv {:?}" ,
583
578
final_ident,
584
579
vis) ;
@@ -609,8 +604,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
609
604
debug ! ( "(building reduced graph for external crate) building module {} {}" ,
610
605
final_ident,
611
606
is_public) ;
612
- let parent_link = self . get_parent_link ( new_parent, name) ;
613
- let module = Module :: new ( parent_link, Some ( def) , true , is_public) ;
607
+ let parent_link = ModuleParentLink ( new_parent, name) ;
608
+ let module = self . new_module ( parent_link, Some ( def) , true , is_public) ;
614
609
child_name_bindings. define_module ( module, DUMMY_SP ) ;
615
610
}
616
611
}
@@ -681,8 +676,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
681
676
}
682
677
683
678
// Define a module if necessary.
684
- let parent_link = self . get_parent_link ( new_parent, name) ;
685
- let module = Module :: new ( parent_link, Some ( def) , true , is_public) ;
679
+ let parent_link = ModuleParentLink ( new_parent, name) ;
680
+ let module = self . new_module ( parent_link, Some ( def) , true , is_public) ;
686
681
child_name_bindings. define_module ( module, DUMMY_SP ) ;
687
682
}
688
683
DefTy ( ..) | DefAssociatedTy ( ..) => {
@@ -728,7 +723,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
728
723
729
724
/// Builds the reduced graph for a single item in an external crate.
730
725
fn build_reduced_graph_for_external_crate_def ( & mut self ,
731
- root : & Rc < Module > ,
726
+ root : Module < ' b > ,
732
727
xcdef : ChildItem ) {
733
728
match xcdef. def {
734
729
DlDef ( def) => {
@@ -766,9 +761,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
766
761
}
767
762
768
763
/// Builds the reduced graph rooted at the given external module.
769
- fn populate_external_module ( & mut self , module : & Rc < Module > ) {
764
+ fn populate_external_module ( & mut self , module : Module < ' b > ) {
770
765
debug ! ( "(populating external module) attempting to populate {}" ,
771
- module_to_string( & * * module) ) ;
766
+ module_to_string( module) ) ;
772
767
773
768
let def_id = match module. def_id ( ) {
774
769
None => {
@@ -788,7 +783,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
788
783
789
784
/// Ensures that the reduced graph rooted at the given external module
790
785
/// is built, building it if it is not.
791
- fn populate_module_if_necessary ( & mut self , module : & Rc < Module > ) {
786
+ fn populate_module_if_necessary ( & mut self , module : Module < ' b > ) {
792
787
if !module. populated . get ( ) {
793
788
self . populate_external_module ( module)
794
789
}
@@ -797,7 +792,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
797
792
798
793
/// Builds the reduced graph rooted at the 'use' directive for an external
799
794
/// crate.
800
- fn build_reduced_graph_for_external_crate ( & mut self , root : & Rc < Module > ) {
795
+ fn build_reduced_graph_for_external_crate ( & mut self , root : Module < ' b > ) {
801
796
let root_cnum = root. def_id ( ) . unwrap ( ) . krate ;
802
797
for child in self . session . cstore . crate_top_level_items ( root_cnum) {
803
798
self . build_reduced_graph_for_external_crate_def ( root, child) ;
@@ -806,7 +801,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
806
801
807
802
/// Creates and adds an import directive to the given module.
808
803
fn build_import_directive ( & mut self ,
809
- module_ : & Module ,
804
+ module_ : Module < ' b > ,
810
805
module_path : Vec < Name > ,
811
806
subclass : ImportDirectiveSubclass ,
812
807
span : Span ,
@@ -866,7 +861,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
866
861
867
862
struct BuildReducedGraphVisitor < ' a , ' b : ' a , ' tcx : ' b > {
868
863
builder : GraphBuilder < ' a , ' b , ' tcx > ,
869
- parent : Rc < Module > ,
864
+ parent : Module < ' b > ,
870
865
}
871
866
872
867
impl < ' a , ' b , ' v , ' tcx > Visitor < ' v > for BuildReducedGraphVisitor < ' a , ' b , ' tcx > {
@@ -897,6 +892,7 @@ pub fn build_reduced_graph(resolver: &mut Resolver, krate: &hir::Crate) {
897
892
GraphBuilder { resolver : resolver } . build_reduced_graph ( krate) ;
898
893
}
899
894
900
- pub fn populate_module_if_necessary ( resolver : & mut Resolver , module : & Rc < Module > ) {
895
+ pub fn populate_module_if_necessary < ' a , ' tcx > ( resolver : & mut Resolver < ' a , ' tcx > ,
896
+ module : Module < ' a > ) {
901
897
GraphBuilder { resolver : resolver } . populate_module_if_necessary ( module) ;
902
898
}
0 commit comments