@@ -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)
@@ -224,12 +209,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
224209 let expansion = parent_scope. expansion ;
225210 // Record primary definitions.
226211 match res {
227- Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
228- let module = self . expect_module ( def_id) ;
229- self . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
230- }
231212 Res :: Def (
232- DefKind :: Struct
213+ DefKind :: Mod
214+ | DefKind :: Enum
215+ | DefKind :: Trait
216+ | DefKind :: Struct
233217 | DefKind :: Union
234218 | DefKind :: Variant
235219 | DefKind :: TyAlias
@@ -776,22 +760,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
776760 }
777761
778762 ItemKind :: Mod ( _, ident, ref mod_kind) => {
779- let module = self . r . new_module (
763+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
764+
765+ if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
766+ self . r . mods_with_parse_errors . insert ( def_id) ;
767+ }
768+ self . parent_scope . module = self . r . new_module (
780769 Some ( parent) ,
781770 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
782771 expansion. to_expn_id ( ) ,
783772 item. span ,
784773 parent. no_implicit_prelude
785774 || ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
786775 ) ;
787- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
788-
789- if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
790- self . r . mods_with_parse_errors . insert ( def_id) ;
791- }
792-
793- // Descend into the module.
794- self . parent_scope . module = module;
795776 }
796777
797778 // These items live in the value namespace.
@@ -814,15 +795,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
814795 }
815796
816797 ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
817- let module = self . r . new_module (
798+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
799+
800+ self . parent_scope . module = self . r . new_module (
818801 Some ( parent) ,
819802 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
820803 expansion. to_expn_id ( ) ,
821804 item. span ,
822805 parent. no_implicit_prelude ,
823806 ) ;
824- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
825- self . parent_scope . module = module;
826807 }
827808
828809 // These items live in both the type and value namespaces.
@@ -930,8 +911,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
930911 }
931912 . map ( |module| {
932913 let used = self . process_macro_use_imports ( item, module) ;
914+ let res = module. res ( ) . unwrap ( ) ;
933915 let vis = ty:: Visibility :: < LocalDefId > :: Public ;
934- let binding = ( module , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
916+ let binding = ( res , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
935917 ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
936918 } )
937919 . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments