@@ -127,7 +127,6 @@ impl<'a> Resolver<'a> {
127
127
/// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum,
128
128
/// or trait), then this function returns that module's resolver representation, otherwise it
129
129
/// returns `None`.
130
- /// FIXME: `Module`s for local enums and traits are not currently found.
131
130
crate fn get_module ( & mut self , def_id : DefId ) -> Option < Module < ' a > > {
132
131
if let module @ Some ( ..) = self . module_map . get ( & def_id) {
133
132
return module. copied ( ) ;
@@ -146,17 +145,21 @@ impl<'a> Resolver<'a> {
146
145
} else {
147
146
def_key. disambiguated_data . data . get_opt_name ( ) . expect ( "module without name" )
148
147
} ;
148
+ let expn_id = if def_kind == DefKind :: Mod {
149
+ self . cstore ( ) . module_expansion_untracked ( def_id, & self . session )
150
+ } else {
151
+ // FIXME: Parent expansions for enums and traits are not kept in metadata.
152
+ ExpnId :: root ( )
153
+ } ;
149
154
150
- let module = self . arenas . new_module (
155
+ Some ( self . new_module (
151
156
parent,
152
157
ModuleKind :: Def ( def_kind, def_id, name) ,
153
- self . cstore ( ) . module_expansion_untracked ( def_id , & self . session ) ,
158
+ expn_id ,
154
159
self . cstore ( ) . get_span_untracked ( def_id, & self . session ) ,
155
160
// FIXME: Account for `#[no_implicit_prelude]` attributes.
156
161
parent. map_or ( false , |module| module. no_implicit_prelude ) ,
157
- ) ;
158
- self . module_map . insert ( def_id, module) ;
159
- Some ( module)
162
+ ) )
160
163
}
161
164
_ => None ,
162
165
}
@@ -217,8 +220,7 @@ impl<'a> Resolver<'a> {
217
220
}
218
221
219
222
crate fn build_reduced_graph_external ( & mut self , module : Module < ' a > ) {
220
- let def_id = module. def_id ( ) . expect ( "unpopulated module without a def-id" ) ;
221
- for child in self . cstore ( ) . item_children_untracked ( def_id, self . session ) {
223
+ for child in self . cstore ( ) . item_children_untracked ( module. def_id ( ) , self . session ) {
222
224
let parent_scope = ParentScope :: module ( module, self ) ;
223
225
BuildReducedGraphVisitor { r : self , parent_scope }
224
226
. build_reduced_graph_for_external_crate_res ( child) ;
@@ -759,7 +761,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
759
761
}
760
762
761
763
ItemKind :: Mod ( ..) => {
762
- let module = self . r . arenas . new_module (
764
+ let module = self . r . new_module (
763
765
Some ( parent) ,
764
766
ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ,
765
767
expansion. to_expn_id ( ) ,
@@ -768,7 +770,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
768
770
|| self . r . session . contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
769
771
) ;
770
772
self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
771
- self . r . module_map . insert ( def_id, module) ;
772
773
773
774
// Descend into the module.
774
775
self . parent_scope . module = module;
@@ -799,7 +800,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
799
800
}
800
801
801
802
ItemKind :: Enum ( _, _) => {
802
- let module = self . r . arenas . new_module (
803
+ let module = self . r . new_module (
803
804
Some ( parent) ,
804
805
ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ,
805
806
expansion. to_expn_id ( ) ,
@@ -873,7 +874,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
873
874
874
875
ItemKind :: Trait ( ..) => {
875
876
// Add all the items within to a new module.
876
- let module = self . r . arenas . new_module (
877
+ let module = self . r . new_module (
877
878
Some ( parent) ,
878
879
ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ,
879
880
expansion. to_expn_id ( ) ,
@@ -916,7 +917,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
916
917
let parent = self . parent_scope . module ;
917
918
let expansion = self . parent_scope . expansion ;
918
919
if self . block_needs_anonymous_module ( block) {
919
- let module = self . r . arenas . new_module (
920
+ let module = self . r . new_module (
920
921
Some ( parent) ,
921
922
ModuleKind :: Block ( block. id ) ,
922
923
expansion. to_expn_id ( ) ,
@@ -936,15 +937,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
936
937
let expansion = self . parent_scope . expansion ;
937
938
// Record primary definitions.
938
939
match res {
939
- Res :: Def ( kind @ ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait ) , def_id) => {
940
- let module = self . r . arenas . new_module (
941
- Some ( parent) ,
942
- ModuleKind :: Def ( kind, def_id, ident. name ) ,
943
- expansion. to_expn_id ( ) ,
944
- span,
945
- // FIXME: Account for `#[no_implicit_prelude]` attributes.
946
- parent. no_implicit_prelude ,
947
- ) ;
940
+ Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
941
+ let module = self . r . expect_module ( def_id) ;
948
942
self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
949
943
}
950
944
Res :: Def (
0 commit comments