@@ -40,21 +40,6 @@ use crate::{
4040
4141type Res = def:: Res < NodeId > ;
4242
43- impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra >
44- for ( Module < ' ra > , ty:: Visibility < Id > , Span , LocalExpnId )
45- {
46- fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
47- arenas. alloc_name_binding ( NameBindingData {
48- kind : NameBindingKind :: Module ( self . 0 ) ,
49- ambiguity : None ,
50- warn_ambiguity : false ,
51- vis : self . 1 . to_def_id ( ) ,
52- span : self . 2 ,
53- expansion : self . 3 ,
54- } )
55- }
56- }
57-
5843impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId ) {
5944 fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
6045 arenas. alloc_name_binding ( NameBindingData {
@@ -122,7 +107,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
122107 if !def_id. is_local ( ) {
123108 // Query `def_kind` is not used because query system overhead is too expensive here.
124109 let def_kind = self . cstore ( ) . def_kind_untracked ( def_id) ;
125- if let DefKind :: Mod | DefKind :: Enum | DefKind :: Trait = def_kind {
110+ if def_kind. is_module_like ( ) {
126111 let parent = self
127112 . tcx
128113 . opt_parent ( def_id)
@@ -222,12 +207,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
222207 let expansion = parent_scope. expansion ;
223208 // Record primary definitions.
224209 match res {
225- Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
226- let module = self . expect_module ( def_id) ;
227- self . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
228- }
229210 Res :: Def (
230- DefKind :: Struct
211+ DefKind :: Mod
212+ | DefKind :: Enum
213+ | DefKind :: Trait
214+ | DefKind :: Struct
231215 | DefKind :: Union
232216 | DefKind :: Variant
233217 | DefKind :: TyAlias
@@ -774,22 +758,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
774758 }
775759
776760 ItemKind :: Mod ( _, ident, ref mod_kind) => {
777- let module = self . r . new_module (
761+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
762+
763+ if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
764+ self . r . mods_with_parse_errors . insert ( def_id) ;
765+ }
766+ self . parent_scope . module = self . r . new_module (
778767 Some ( parent) ,
779768 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
780769 expansion. to_expn_id ( ) ,
781770 item. span ,
782771 parent. no_implicit_prelude
783772 || ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
784773 ) ;
785- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
786-
787- if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
788- self . r . mods_with_parse_errors . insert ( def_id) ;
789- }
790-
791- // Descend into the module.
792- self . parent_scope . module = module;
793774 }
794775
795776 // These items live in the value namespace.
@@ -812,15 +793,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
812793 }
813794
814795 ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
815- let module = self . r . new_module (
796+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
797+
798+ self . parent_scope . module = self . r . new_module (
816799 Some ( parent) ,
817800 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
818801 expansion. to_expn_id ( ) ,
819802 item. span ,
820803 parent. no_implicit_prelude ,
821804 ) ;
822- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
823- self . parent_scope . module = module;
824805 }
825806
826807 // These items live in both the type and value namespaces.
@@ -928,8 +909,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
928909 }
929910 . map ( |module| {
930911 let used = self . process_macro_use_imports ( item, module) ;
912+ let res = module. res ( ) . unwrap ( ) ;
931913 let vis = ty:: Visibility :: < LocalDefId > :: Public ;
932- let binding = ( module , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
914+ let binding = ( res , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
933915 ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
934916 } )
935917 . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments