@@ -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
}
@@ -759,7 +762,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
759
762
}
760
763
761
764
ItemKind :: Mod ( ..) => {
762
- let module = self . r . arenas . new_module (
765
+ let module = self . r . new_module (
763
766
Some ( parent) ,
764
767
ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ,
765
768
expansion. to_expn_id ( ) ,
@@ -768,7 +771,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
768
771
|| self . r . session . contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
769
772
) ;
770
773
self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
771
- self . r . module_map . insert ( def_id, module) ;
772
774
773
775
// Descend into the module.
774
776
self . parent_scope . module = module;
@@ -799,7 +801,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
799
801
}
800
802
801
803
ItemKind :: Enum ( _, _) => {
802
- let module = self . r . arenas . new_module (
804
+ let module = self . r . new_module (
803
805
Some ( parent) ,
804
806
ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ,
805
807
expansion. to_expn_id ( ) ,
@@ -873,7 +875,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
873
875
874
876
ItemKind :: Trait ( ..) => {
875
877
// Add all the items within to a new module.
876
- let module = self . r . arenas . new_module (
878
+ let module = self . r . new_module (
877
879
Some ( parent) ,
878
880
ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ,
879
881
expansion. to_expn_id ( ) ,
@@ -916,7 +918,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
916
918
let parent = self . parent_scope . module ;
917
919
let expansion = self . parent_scope . expansion ;
918
920
if self . block_needs_anonymous_module ( block) {
919
- let module = self . r . arenas . new_module (
921
+ let module = self . r . new_module (
920
922
Some ( parent) ,
921
923
ModuleKind :: Block ( block. id ) ,
922
924
expansion. to_expn_id ( ) ,
@@ -936,15 +938,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
936
938
let expansion = self . parent_scope . expansion ;
937
939
// Record primary definitions.
938
940
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
- ) ;
941
+ Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
942
+ let module = self . r . expect_module ( def_id) ;
948
943
self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
949
944
}
950
945
Res :: Def (
0 commit comments