@@ -23,7 +23,6 @@ use Namespace::{TypeNS, ValueNS};
23
23
use NameBindings ;
24
24
use ParentLink :: { mod, ModuleParentLink , BlockParentLink } ;
25
25
use Resolver ;
26
- use ReducedGraphParent :: { mod, ModuleReducedGraphParent } ;
27
26
use RibKind :: * ;
28
27
use Shadowable ;
29
28
use TypeNsDef ;
@@ -111,7 +110,7 @@ impl<'a, 'b:'a, 'tcx:'b> DerefMut<Resolver<'b, 'tcx>> for GraphBuilder<'a, 'b, '
111
110
impl < ' a , ' b : ' a , ' tcx : ' b > GraphBuilder < ' a , ' b , ' tcx > {
112
111
/// Constructs the reduced graph for the entire crate.
113
112
fn build_reduced_graph ( self , krate : & ast:: Crate ) {
114
- let parent = ModuleReducedGraphParent ( self . graph_root . get_module ( ) ) ;
113
+ let parent = self . graph_root . get_module ( ) ;
115
114
let mut visitor = BuildReducedGraphVisitor {
116
115
builder : self ,
117
116
parent : parent
@@ -131,7 +130,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
131
130
/// a block.
132
131
fn add_child ( & self ,
133
132
name : Name ,
134
- reduced_graph_parent : ReducedGraphParent ,
133
+ parent : Rc < Module > ,
135
134
duplicate_checking_mode : DuplicateCheckingMode ,
136
135
// For printing errors
137
136
sp : Span )
@@ -140,18 +139,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
140
139
// child name directly. Otherwise, we create or reuse an anonymous
141
140
// module and add the child to that.
142
141
143
- let module_ = reduced_graph_parent. module ( ) ;
144
-
145
- self . check_for_conflicts_between_external_crates_and_items ( & * module_,
142
+ self . check_for_conflicts_between_external_crates_and_items ( & * parent,
146
143
name,
147
144
sp) ;
148
145
149
146
// Add or reuse the child.
150
- let child = module_ . children . borrow ( ) . get ( & name) . cloned ( ) ;
147
+ let child = parent . children . borrow ( ) . get ( & name) . cloned ( ) ;
151
148
match child {
152
149
None => {
153
150
let child = Rc :: new ( NameBindings :: new ( ) ) ;
154
- module_ . children . borrow_mut ( ) . insert ( name, child. clone ( ) ) ;
151
+ parent . children . borrow_mut ( ) . insert ( name, child. clone ( ) ) ;
155
152
child
156
153
}
157
154
Some ( child) => {
@@ -268,20 +265,16 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
268
265
return false ;
269
266
}
270
267
271
- fn get_parent_link ( & mut self , parent : ReducedGraphParent , name : Name )
268
+ fn get_parent_link ( & mut self , parent : Rc < Module > , name : Name )
272
269
-> ParentLink {
273
- match parent {
274
- ModuleReducedGraphParent ( module_) => {
275
- return ModuleParentLink ( module_. downgrade ( ) , name) ;
276
- }
277
- }
270
+ ModuleParentLink ( parent. downgrade ( ) , name)
278
271
}
279
272
280
273
/// Constructs the reduced graph for one item.
281
274
fn build_reduced_graph_for_item ( & mut self ,
282
275
item : & Item ,
283
- parent : ReducedGraphParent )
284
- -> ReducedGraphParent
276
+ parent : Rc < Module > )
277
+ -> Rc < Module >
285
278
{
286
279
let name = item. ident . name ;
287
280
let sp = item. span ;
@@ -302,7 +295,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
302
295
item. vis == ast:: Public ,
303
296
sp) ;
304
297
305
- ModuleReducedGraphParent ( name_bindings. get_module ( ) )
298
+ name_bindings. get_module ( )
306
299
}
307
300
308
301
ItemForeignMod ( ..) => parent,
@@ -370,7 +363,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
370
363
self . build_reduced_graph_for_variant (
371
364
& * * variant,
372
365
local_def ( item. id ) ,
373
- ModuleReducedGraphParent ( name_bindings. get_module ( ) ) ) ;
366
+ name_bindings. get_module ( ) ) ;
374
367
}
375
368
parent
376
369
}
@@ -446,22 +439,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
446
439
}
447
440
Some ( mod_name) => {
448
441
// Create the module and add all methods.
449
- let parent_opt = parent. module ( ) . children . borrow ( )
450
- . get ( & mod_name) . cloned ( ) ;
442
+ let parent_opt = parent. children . borrow ( ) . get ( & mod_name) . cloned ( ) ;
451
443
let new_parent = match parent_opt {
452
444
// It already exists
453
445
Some ( ref child) if child. get_module_if_available ( )
454
446
. is_some ( ) &&
455
447
( child. get_module ( ) . kind . get ( ) == ImplModuleKind ||
456
448
child. get_module ( ) . kind . get ( ) == TraitModuleKind ) => {
457
- ModuleReducedGraphParent ( child. get_module ( ) )
449
+ child. get_module ( )
458
450
}
459
451
Some ( ref child) if child. get_module_if_available ( )
460
452
. is_some ( ) &&
461
453
child. get_module ( ) . kind . get ( ) ==
462
- EnumModuleKind => {
463
- ModuleReducedGraphParent ( child. get_module ( ) )
464
- }
454
+ EnumModuleKind => child. get_module ( ) ,
465
455
// Create the module
466
456
_ => {
467
457
let name_bindings =
@@ -485,8 +475,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
485
475
is_public,
486
476
sp) ;
487
477
488
- ModuleReducedGraphParent (
489
- name_bindings. get_module ( ) )
478
+ name_bindings. get_module ( )
490
479
}
491
480
} ;
492
481
@@ -576,8 +565,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
576
565
false ,
577
566
item. vis == ast:: Public ,
578
567
sp) ;
579
- let module_parent = ModuleReducedGraphParent ( name_bindings.
580
- get_module ( ) ) ;
568
+ let module_parent = name_bindings. get_module ( ) ;
581
569
582
570
let def_id = local_def ( item. id ) ;
583
571
@@ -654,7 +642,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
654
642
fn build_reduced_graph_for_variant ( & mut self ,
655
643
variant : & Variant ,
656
644
item_id : DefId ,
657
- parent : ReducedGraphParent ) {
645
+ parent : Rc < Module > ) {
658
646
let name = variant. node . name . name ;
659
647
let is_exported = match variant. node . kind {
660
648
TupleVariantKind ( _) => false ,
@@ -680,8 +668,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
680
668
681
669
/// Constructs the reduced graph for one 'view item'. View items consist
682
670
/// of imports and use directives.
683
- fn build_reduced_graph_for_view_item ( & mut self , view_item : & ViewItem ,
684
- parent : ReducedGraphParent ) {
671
+ fn build_reduced_graph_for_view_item ( & mut self , view_item : & ViewItem , parent : Rc < Module > ) {
685
672
match view_item. node {
686
673
ViewItemUse ( ref view_path) => {
687
674
// Extract and intern the module part of the path. For
@@ -703,7 +690,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
703
690
} ;
704
691
705
692
// Build up the import directives.
706
- let module_ = parent. module ( ) ;
707
693
let is_public = view_item. vis == ast:: Public ;
708
694
let shadowable =
709
695
view_item. attrs
@@ -729,7 +715,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
729
715
730
716
let subclass = SingleImport ( binding. name ,
731
717
source_name) ;
732
- self . build_import_directive ( & * module_ ,
718
+ self . build_import_directive ( & * parent ,
733
719
module_path,
734
720
subclass,
735
721
view_path. span ,
@@ -771,7 +757,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
771
757
}
772
758
} ;
773
759
self . build_import_directive (
774
- & * module_ ,
760
+ & * parent ,
775
761
module_path,
776
762
SingleImport ( name, name) ,
777
763
source_item. span ,
@@ -781,7 +767,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
781
767
}
782
768
}
783
769
ViewPathGlob ( _, id) => {
784
- self . build_import_directive ( & * module_ ,
770
+ self . build_import_directive ( & * parent ,
785
771
module_path,
786
772
GlobImport ,
787
773
view_path. span ,
@@ -798,8 +784,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
798
784
. find_extern_mod_stmt_cnum ( node_id) . iter ( ) {
799
785
let def_id = DefId { krate : crate_id, node : 0 } ;
800
786
self . external_exports . insert ( def_id) ;
801
- let parent_link =
802
- ModuleParentLink ( parent. module ( ) . downgrade ( ) , name. name ) ;
787
+ let parent_link = ModuleParentLink ( parent. downgrade ( ) , name. name ) ;
803
788
let external_module = Rc :: new ( Module :: new ( parent_link,
804
789
Some ( def_id) ,
805
790
NormalModuleKind ,
@@ -808,11 +793,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
808
793
debug ! ( "(build reduced graph for item) found extern `{}`" ,
809
794
self . module_to_string( & * external_module) ) ;
810
795
self . check_for_conflicts_between_external_crates (
811
- & * parent. module ( ) ,
796
+ & * parent,
812
797
name. name ,
813
798
view_item. span ) ;
814
- parent. module ( ) . external_module_children . borrow_mut ( )
815
- . insert ( name. name , external_module. clone ( ) ) ;
799
+ parent. external_module_children . borrow_mut ( )
800
+ . insert ( name. name , external_module. clone ( ) ) ;
816
801
self . build_reduced_graph_for_external_crate ( external_module) ;
817
802
}
818
803
}
@@ -822,7 +807,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
822
807
/// Constructs the reduced graph for one foreign item.
823
808
fn build_reduced_graph_for_foreign_item < F > ( & mut self ,
824
809
foreign_item : & ForeignItem ,
825
- parent : ReducedGraphParent ,
810
+ parent : Rc < Module > ,
826
811
f : F ) where
827
812
F : FnOnce ( & mut Resolver ) ,
828
813
{
@@ -854,28 +839,22 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
854
839
}
855
840
}
856
841
857
- fn build_reduced_graph_for_block ( & mut self ,
858
- block : & Block ,
859
- parent : ReducedGraphParent )
860
- -> ReducedGraphParent
861
- {
842
+ fn build_reduced_graph_for_block ( & mut self , block : & Block , parent : Rc < Module > ) -> Rc < Module > {
862
843
if self . block_needs_anonymous_module ( block) {
863
844
let block_id = block. id ;
864
845
865
846
debug ! ( "(building reduced graph for block) creating a new \
866
847
anonymous module for block {}",
867
848
block_id) ;
868
849
869
- let parent_module = parent. module ( ) ;
870
850
let new_module = Rc :: new ( Module :: new (
871
- BlockParentLink ( parent_module . downgrade ( ) , block_id) ,
851
+ BlockParentLink ( parent . downgrade ( ) , block_id) ,
872
852
None ,
873
853
AnonymousModuleKind ,
874
854
false ,
875
855
false ) ) ;
876
- parent_module. anonymous_children . borrow_mut ( )
877
- . insert ( block_id, new_module. clone ( ) ) ;
878
- ModuleReducedGraphParent ( new_module)
856
+ parent. anonymous_children . borrow_mut ( ) . insert ( block_id, new_module. clone ( ) ) ;
857
+ new_module
879
858
} else {
880
859
parent
881
860
}
@@ -887,19 +866,15 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
887
866
child_name_bindings : & NameBindings ,
888
867
final_ident : & str ,
889
868
name : Name ,
890
- new_parent : ReducedGraphParent ) {
869
+ new_parent : Rc < Module > ) {
891
870
debug ! ( "(building reduced graph for \
892
871
external crate) building external def, priv {}",
893
872
vis) ;
894
873
let is_public = vis == ast:: Public ;
895
874
let modifiers = if is_public { PUBLIC } else { DefModifiers :: empty ( ) } | IMPORTABLE ;
896
- let is_exported = is_public && match new_parent {
897
- ModuleReducedGraphParent ( ref module) => {
898
- match module. def_id . get ( ) {
899
- None => true ,
900
- Some ( did) => self . external_exports . contains ( & did)
901
- }
902
- }
875
+ let is_exported = is_public && match new_parent. def_id . get ( ) {
876
+ None => true ,
877
+ Some ( did) => self . external_exports . contains ( & did)
903
878
} ;
904
879
if is_exported {
905
880
self . external_exports . insert ( def. def_id ( ) ) ;
@@ -969,7 +944,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
969
944
Some ( ref def) => ( modifiers & !IMPORTABLE ) | ( def. modifiers & IMPORTABLE ) ,
970
945
None => modifiers
971
946
} ;
972
- if new_parent. module ( ) . kind . get ( ) != NormalModuleKind {
947
+ if new_parent. kind . get ( ) != NormalModuleKind {
973
948
modifiers = modifiers & !IMPORTABLE ;
974
949
}
975
950
child_name_bindings. define_value ( def, DUMMY_SP , modifiers) ;
@@ -1070,7 +1045,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
1070
1045
_ => {
1071
1046
let child_name_bindings =
1072
1047
self . add_child ( name,
1073
- ModuleReducedGraphParent ( root. clone ( ) ) ,
1048
+ root. clone ( ) ,
1074
1049
OverwriteDuplicates ,
1075
1050
DUMMY_SP ) ;
1076
1051
@@ -1079,7 +1054,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
1079
1054
& * child_name_bindings,
1080
1055
token:: get_name ( name) . get ( ) ,
1081
1056
name,
1082
- ModuleReducedGraphParent ( root) ) ;
1057
+ root) ;
1083
1058
}
1084
1059
}
1085
1060
}
@@ -1100,7 +1075,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
1100
1075
let child_name_bindings =
1101
1076
self . add_child (
1102
1077
final_name,
1103
- ModuleReducedGraphParent ( root. clone ( ) ) ,
1078
+ root. clone ( ) ,
1104
1079
OverwriteDuplicates ,
1105
1080
DUMMY_SP ) ;
1106
1081
@@ -1123,8 +1098,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
1123
1098
}
1124
1099
Some ( _) | None => {
1125
1100
let parent_link =
1126
- self . get_parent_link ( ModuleReducedGraphParent ( root) ,
1127
- final_name) ;
1101
+ self . get_parent_link ( root, final_name) ;
1128
1102
child_name_bindings. define_module (
1129
1103
parent_link,
1130
1104
Some ( def) ,
@@ -1139,8 +1113,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
1139
1113
}
1140
1114
1141
1115
// Add each static method to the module.
1142
- let new_parent =
1143
- ModuleReducedGraphParent ( type_module) ;
1116
+ let new_parent = type_module;
1144
1117
for method_info in methods. iter ( ) {
1145
1118
let name = method_info. name ;
1146
1119
debug ! ( "(building reduced graph for \
@@ -1290,7 +1263,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
1290
1263
1291
1264
struct BuildReducedGraphVisitor < ' a , ' b : ' a , ' tcx : ' b > {
1292
1265
builder : GraphBuilder < ' a , ' b , ' tcx > ,
1293
- parent : ReducedGraphParent
1266
+ parent : Rc < Module >
1294
1267
}
1295
1268
1296
1269
impl < ' a , ' b , ' v , ' tcx > Visitor < ' v > for BuildReducedGraphVisitor < ' a , ' b , ' tcx > {
0 commit comments