@@ -127,7 +127,6 @@ impl<'a> Resolver<'a> {
127127 /// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum,
128128 /// or trait), then this function returns that module's resolver representation, otherwise it
129129 /// returns `None`.
130- /// FIXME: `Module`s for local enums and traits are not currently found.
131130 crate fn get_module ( & mut self , def_id : DefId ) -> Option < Module < ' a > > {
132131 if let module @ Some ( ..) = self . module_map . get ( & def_id) {
133132 return module. copied ( ) ;
@@ -146,17 +145,21 @@ impl<'a> Resolver<'a> {
146145 } else {
147146 def_key. disambiguated_data . data . get_opt_name ( ) . expect ( "module without name" )
148147 } ;
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+ } ;
149154
150- let module = self . arenas . new_module (
155+ Some ( self . new_module (
151156 parent,
152157 ModuleKind :: Def ( def_kind, def_id, name) ,
153- self . cstore ( ) . module_expansion_untracked ( def_id , & self . session ) ,
158+ expn_id ,
154159 self . cstore ( ) . get_span_untracked ( def_id, & self . session ) ,
155160 // FIXME: Account for `#[no_implicit_prelude]` attributes.
156161 parent. map_or ( false , |module| module. no_implicit_prelude ) ,
157- ) ;
158- self . module_map . insert ( def_id, module) ;
159- Some ( module)
162+ ) )
160163 }
161164 _ => None ,
162165 }
@@ -217,8 +220,7 @@ impl<'a> Resolver<'a> {
217220 }
218221
219222 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 ) {
222224 let parent_scope = ParentScope :: module ( module, self ) ;
223225 BuildReducedGraphVisitor { r : self , parent_scope }
224226 . build_reduced_graph_for_external_crate_res ( child) ;
@@ -759,7 +761,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
759761 }
760762
761763 ItemKind :: Mod ( ..) => {
762- let module = self . r . arenas . new_module (
764+ let module = self . r . new_module (
763765 Some ( parent) ,
764766 ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ,
765767 expansion. to_expn_id ( ) ,
@@ -768,7 +770,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
768770 || self . r . session . contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
769771 ) ;
770772 self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
771- self . r . module_map . insert ( def_id, module) ;
772773
773774 // Descend into the module.
774775 self . parent_scope . module = module;
@@ -799,7 +800,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
799800 }
800801
801802 ItemKind :: Enum ( _, _) => {
802- let module = self . r . arenas . new_module (
803+ let module = self . r . new_module (
803804 Some ( parent) ,
804805 ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ,
805806 expansion. to_expn_id ( ) ,
@@ -873,7 +874,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
873874
874875 ItemKind :: Trait ( ..) => {
875876 // Add all the items within to a new module.
876- let module = self . r . arenas . new_module (
877+ let module = self . r . new_module (
877878 Some ( parent) ,
878879 ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ,
879880 expansion. to_expn_id ( ) ,
@@ -916,7 +917,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
916917 let parent = self . parent_scope . module ;
917918 let expansion = self . parent_scope . expansion ;
918919 if self . block_needs_anonymous_module ( block) {
919- let module = self . r . arenas . new_module (
920+ let module = self . r . new_module (
920921 Some ( parent) ,
921922 ModuleKind :: Block ( block. id ) ,
922923 expansion. to_expn_id ( ) ,
@@ -936,15 +937,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
936937 let expansion = self . parent_scope . expansion ;
937938 // Record primary definitions.
938939 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) ;
948942 self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
949943 }
950944 Res :: Def (
0 commit comments