@@ -39,21 +39,6 @@ use crate::{
3939
4040type Res = def:: Res < NodeId > ;
4141
42- impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra >
43- for ( Module < ' ra > , ty:: Visibility < Id > , Span , LocalExpnId )
44- {
45- fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
46- arenas. alloc_name_binding ( NameBindingData {
47- kind : NameBindingKind :: Module ( self . 0 ) ,
48- ambiguity : None ,
49- warn_ambiguity : false ,
50- vis : self . 1 . to_def_id ( ) ,
51- span : self . 2 ,
52- expansion : self . 3 ,
53- } )
54- }
55- }
56-
5742impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId ) {
5843 fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
5944 arenas. alloc_name_binding ( NameBindingData {
@@ -121,7 +106,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
121106 if !def_id. is_local ( ) {
122107 // Query `def_kind` is not used because query system overhead is too expensive here.
123108 let def_kind = self . cstore ( ) . def_kind_untracked ( def_id) ;
124- if let DefKind :: Mod | DefKind :: Enum | DefKind :: Trait = def_kind {
109+ if def_kind. is_module_like ( ) {
125110 let parent = self
126111 . tcx
127112 . opt_parent ( def_id)
@@ -223,12 +208,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
223208 let expansion = parent_scope. expansion ;
224209 // Record primary definitions.
225210 match res {
226- Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
227- let module = self . expect_module ( def_id) ;
228- self . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
229- }
230211 Res :: Def (
231- DefKind :: Struct
212+ DefKind :: Mod
213+ | DefKind :: Enum
214+ | DefKind :: Trait
215+ | DefKind :: Struct
232216 | DefKind :: Union
233217 | DefKind :: Variant
234218 | DefKind :: TyAlias
@@ -766,22 +750,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
766750 }
767751
768752 ItemKind :: Mod ( _, ident, ref mod_kind) => {
769- let module = self . r . new_module (
753+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
754+
755+ if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
756+ self . r . mods_with_parse_errors . insert ( def_id) ;
757+ }
758+ self . parent_scope . module = self . r . new_module (
770759 Some ( parent) ,
771760 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
772761 expansion. to_expn_id ( ) ,
773762 item. span ,
774763 parent. no_implicit_prelude
775764 || ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
776765 ) ;
777- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
778-
779- if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
780- self . r . mods_with_parse_errors . insert ( def_id) ;
781- }
782-
783- // Descend into the module.
784- self . parent_scope . module = module;
785766 }
786767
787768 // These items live in the value namespace.
@@ -804,15 +785,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
804785 }
805786
806787 ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
807- let module = self . r . new_module (
788+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
789+
790+ self . parent_scope . module = self . r . new_module (
808791 Some ( parent) ,
809792 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
810793 expansion. to_expn_id ( ) ,
811794 item. span ,
812795 parent. no_implicit_prelude ,
813796 ) ;
814- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
815- self . parent_scope . module = module;
816797 }
817798
818799 // These items live in both the type and value namespaces.
@@ -920,8 +901,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
920901 }
921902 . map ( |module| {
922903 let used = self . process_macro_use_imports ( item, module) ;
904+ let res = module. res ( ) . unwrap ( ) ;
923905 let vis = ty:: Visibility :: < LocalDefId > :: Public ;
924- let binding = ( module , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
906+ let binding = ( res , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
925907 ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
926908 } )
927909 . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments