@@ -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 }
@@ -759,7 +762,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
759762 }
760763
761764 ItemKind :: Mod ( ..) => {
762- let module = self . r . arenas . new_module (
765+ let module = self . r . new_module (
763766 Some ( parent) ,
764767 ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ,
765768 expansion. to_expn_id ( ) ,
@@ -768,7 +771,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
768771 || self . r . session . contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
769772 ) ;
770773 self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
771- self . r . module_map . insert ( def_id, module) ;
772774
773775 // Descend into the module.
774776 self . parent_scope . module = module;
@@ -799,7 +801,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
799801 }
800802
801803 ItemKind :: Enum ( _, _) => {
802- let module = self . r . arenas . new_module (
804+ let module = self . r . new_module (
803805 Some ( parent) ,
804806 ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ,
805807 expansion. to_expn_id ( ) ,
@@ -873,7 +875,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
873875
874876 ItemKind :: Trait ( ..) => {
875877 // Add all the items within to a new module.
876- let module = self . r . arenas . new_module (
878+ let module = self . r . new_module (
877879 Some ( parent) ,
878880 ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ,
879881 expansion. to_expn_id ( ) ,
@@ -916,7 +918,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
916918 let parent = self . parent_scope . module ;
917919 let expansion = self . parent_scope . expansion ;
918920 if self . block_needs_anonymous_module ( block) {
919- let module = self . r . arenas . new_module (
921+ let module = self . r . new_module (
920922 Some ( parent) ,
921923 ModuleKind :: Block ( block. id ) ,
922924 expansion. to_expn_id ( ) ,
@@ -936,15 +938,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
936938 let expansion = self . parent_scope . expansion ;
937939 // Record primary definitions.
938940 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) ;
948943 self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
949944 }
950945 Res :: Def (
0 commit comments