@@ -18,7 +18,6 @@ use resolve_imports::ImportDirective;
18
18
use resolve_imports:: ImportDirectiveSubclass :: { self , SingleImport , GlobImport } ;
19
19
use resolve_imports:: ImportResolution ;
20
20
use Module ;
21
- use ModuleKind :: * ;
22
21
use Namespace :: { TypeNS , ValueNS } ;
23
22
use NameBindings ;
24
23
use { names_to_string, module_to_string} ;
@@ -395,8 +394,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
395
394
self . external_exports . insert ( def_id) ;
396
395
let parent_link = ModuleParentLink ( Rc :: downgrade ( parent) , name) ;
397
396
let external_module = Rc :: new ( Module :: new ( parent_link,
398
- Some ( def_id) ,
399
- NormalModuleKind ,
397
+ Some ( DefMod ( def_id) ) ,
400
398
false ,
401
399
true ) ) ;
402
400
debug ! ( "(build reduced graph for item) found extern `{}`" ,
@@ -436,13 +434,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
436
434
let name_bindings = self . add_child ( name, parent, ForbidDuplicateModules , sp) ;
437
435
438
436
let parent_link = self . get_parent_link ( parent, name) ;
439
- let def_id = self . ast_map . local_def_id ( item. id ) ;
440
- name_bindings. define_module ( parent_link,
441
- Some ( def_id) ,
442
- NormalModuleKind ,
443
- false ,
444
- is_public,
445
- sp) ;
437
+ let def = DefMod ( self . ast_map . local_def_id ( item. id ) ) ;
438
+ name_bindings. define_module ( parent_link, Some ( def) , false , is_public, sp) ;
446
439
447
440
name_bindings. get_module ( )
448
441
}
@@ -479,17 +472,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
479
472
ForbidDuplicateTypesAndModules ,
480
473
sp) ;
481
474
482
- name_bindings. define_type ( DefTy ( self . ast_map . local_def_id ( item. id ) , false ) ,
483
- sp,
484
- modifiers) ;
485
-
486
475
let parent_link = self . get_parent_link ( parent, name) ;
487
- name_bindings. set_module_kind ( parent_link,
488
- Some ( self . ast_map . local_def_id ( item. id ) ) ,
489
- TypeModuleKind ,
490
- false ,
491
- is_public,
492
- sp) ;
476
+ let def = DefTy ( self . ast_map . local_def_id ( item. id ) , false ) ;
477
+ name_bindings. define_module ( parent_link, Some ( def) , false , is_public, sp) ;
493
478
parent. clone ( )
494
479
}
495
480
@@ -499,17 +484,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
499
484
ForbidDuplicateTypesAndModules ,
500
485
sp) ;
501
486
502
- name_bindings. define_type ( DefTy ( self . ast_map . local_def_id ( item. id ) , true ) ,
503
- sp,
504
- modifiers) ;
505
-
506
487
let parent_link = self . get_parent_link ( parent, name) ;
507
- name_bindings. set_module_kind ( parent_link,
508
- Some ( self . ast_map . local_def_id ( item. id ) ) ,
509
- EnumModuleKind ,
510
- false ,
511
- is_public,
512
- sp) ;
488
+ let def = DefTy ( self . ast_map . local_def_id ( item. id ) , true ) ;
489
+ name_bindings. define_module ( parent_link, Some ( def) , false , is_public, sp) ;
513
490
514
491
let module = name_bindings. get_module ( ) ;
515
492
@@ -592,18 +569,14 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
592
569
ForbidDuplicateTypesAndModules ,
593
570
sp) ;
594
571
572
+ let def_id = self . ast_map . local_def_id ( item. id ) ;
573
+
595
574
// Add all the items within to a new module.
596
575
let parent_link = self . get_parent_link ( parent, name) ;
597
- name_bindings. define_module ( parent_link,
598
- Some ( self . ast_map . local_def_id ( item. id ) ) ,
599
- TraitModuleKind ,
600
- false ,
601
- is_public,
602
- sp) ;
576
+ let def = DefTrait ( def_id) ;
577
+ name_bindings. define_module ( parent_link, Some ( def) , false , is_public, sp) ;
603
578
let module_parent = name_bindings. get_module ( ) ;
604
579
605
- let def_id = self . ast_map . local_def_id ( item. id ) ;
606
-
607
580
// Add the names of all the items to the trait info.
608
581
for trait_item in items {
609
582
let name_bindings = self . add_child ( trait_item. name ,
@@ -634,7 +607,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
634
607
self . trait_item_map . insert ( ( trait_item. name , def_id) , trait_item_def_id) ;
635
608
}
636
609
637
- name_bindings. define_type ( DefTrait ( def_id) , sp, modifiers) ;
638
610
parent. clone ( )
639
611
}
640
612
}
@@ -705,7 +677,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
705
677
706
678
let new_module = Rc :: new ( Module :: new ( BlockParentLink ( Rc :: downgrade ( parent) , block_id) ,
707
679
None ,
708
- AnonymousModuleKind ,
709
680
false ,
710
681
false ) ) ;
711
682
parent. anonymous_children . borrow_mut ( ) . insert ( block_id, new_module. clone ( ) ) ;
@@ -732,37 +703,30 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
732
703
DefModifiers :: empty ( )
733
704
} | DefModifiers :: IMPORTABLE ;
734
705
let is_exported = is_public &&
735
- match new_parent. def_id . get ( ) {
706
+ match new_parent. def_id ( ) {
736
707
None => true ,
737
708
Some ( did) => self . external_exports . contains ( & did) ,
738
709
} ;
739
710
if is_exported {
740
711
self . external_exports . insert ( def. def_id ( ) ) ;
741
712
}
742
713
743
- let kind = match def {
744
- DefTy ( _, true ) => EnumModuleKind ,
745
- DefTy ( _, false ) | DefStruct ( ..) => TypeModuleKind ,
746
- _ => NormalModuleKind ,
747
- } ;
748
-
749
714
match def {
750
- DefMod ( def_id ) |
751
- DefForeignMod ( def_id ) |
752
- DefStruct ( def_id ) |
753
- DefTy ( def_id , _ ) => {
715
+ DefMod ( _ ) |
716
+ DefForeignMod ( _ ) |
717
+ DefStruct ( _ ) |
718
+ DefTy ( .. ) => {
754
719
if let Some ( module_def) = child_name_bindings. type_ns . module ( ) {
755
720
debug ! ( "(building reduced graph for external crate) already created module" ) ;
756
- module_def. def_id . set ( Some ( def_id ) ) ;
721
+ module_def. def . set ( Some ( def ) ) ;
757
722
} else {
758
723
debug ! ( "(building reduced graph for external crate) building module {} {}" ,
759
724
final_ident,
760
725
is_public) ;
761
726
let parent_link = self . get_parent_link ( new_parent, name) ;
762
727
763
728
child_name_bindings. define_module ( parent_link,
764
- Some ( def_id) ,
765
- kind,
729
+ Some ( def) ,
766
730
true ,
767
731
is_public,
768
732
DUMMY_SP ) ;
@@ -806,7 +770,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
806
770
( def. modifiers & DefModifiers :: IMPORTABLE ) ,
807
771
None => modifiers,
808
772
} ;
809
- if new_parent. kind . get ( ) != NormalModuleKind {
773
+ if ! new_parent. is_normal ( ) {
810
774
modifiers = modifiers & !DefModifiers :: IMPORTABLE ;
811
775
}
812
776
child_name_bindings. define_value ( def, DUMMY_SP , modifiers) ;
@@ -835,33 +799,33 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
835
799
}
836
800
}
837
801
838
- child_name_bindings. define_type ( def, DUMMY_SP , modifiers) ;
839
-
840
802
// Define a module if necessary.
841
803
let parent_link = self . get_parent_link ( new_parent, name) ;
842
- child_name_bindings. set_module_kind ( parent_link,
843
- Some ( def_id) ,
844
- TraitModuleKind ,
845
- true ,
846
- is_public,
847
- DUMMY_SP )
804
+ child_name_bindings. define_module ( parent_link,
805
+ Some ( def) ,
806
+ true ,
807
+ is_public,
808
+ DUMMY_SP )
848
809
}
849
810
DefTy ( ..) | DefAssociatedTy ( ..) => {
850
811
debug ! ( "(building reduced graph for external crate) building type {}" ,
851
812
final_ident) ;
852
813
853
- let modifiers = match new_parent. kind . get ( ) {
854
- NormalModuleKind => modifiers,
814
+ let modifiers = match new_parent. is_normal ( ) {
815
+ true => modifiers,
855
816
_ => modifiers & !DefModifiers :: IMPORTABLE ,
856
817
} ;
857
818
858
- child_name_bindings. define_type ( def, DUMMY_SP , modifiers) ;
819
+ if let DefTy ( ..) = def {
820
+ child_name_bindings. type_ns . set_modifiers ( modifiers) ;
821
+ } else {
822
+ child_name_bindings. define_type ( def, DUMMY_SP , modifiers) ;
823
+ }
859
824
}
860
825
DefStruct ( def_id) => {
861
826
debug ! ( "(building reduced graph for external crate) building type and value for \
862
827
{}",
863
828
final_ident) ;
864
- child_name_bindings. define_type ( def, DUMMY_SP , modifiers) ;
865
829
let fields = csearch:: get_struct_field_names ( & self . session . cstore , def_id) ;
866
830
867
831
if fields. is_empty ( ) {
@@ -937,7 +901,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
937
901
debug ! ( "(populating external module) attempting to populate {}" ,
938
902
module_to_string( & * * module) ) ;
939
903
940
- let def_id = match module. def_id . get ( ) {
904
+ let def_id = match module. def_id ( ) {
941
905
None => {
942
906
debug ! ( "(populating external module) ... no def ID!" ) ;
943
907
return ;
@@ -971,8 +935,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
971
935
/// crate.
972
936
fn build_reduced_graph_for_external_crate ( & mut self , root : & Rc < Module > ) {
973
937
csearch:: each_top_level_item_of_crate ( & self . session . cstore ,
974
- root. def_id
975
- . get ( )
938
+ root. def_id ( )
976
939
. unwrap ( )
977
940
. krate ,
978
941
|def_like, name, visibility| {
0 commit comments