@@ -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)
@@ -221,12 +206,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
221206 let expansion = parent_scope. expansion ;
222207 // Record primary definitions.
223208 match res {
224- Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
225- let module = self . expect_module ( def_id) ;
226- self . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
227- }
228209 Res :: Def (
229- DefKind :: Struct
210+ DefKind :: Mod
211+ | DefKind :: Enum
212+ | DefKind :: Trait
213+ | DefKind :: Struct
230214 | DefKind :: Union
231215 | DefKind :: Variant
232216 | DefKind :: TyAlias
@@ -773,22 +757,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
773757 }
774758
775759 ItemKind :: Mod ( _, ident, ref mod_kind) => {
776- let module = self . r . new_module (
760+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
761+
762+ if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
763+ self . r . mods_with_parse_errors . insert ( def_id) ;
764+ }
765+ self . parent_scope . module = self . r . new_module (
777766 Some ( parent) ,
778767 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
779768 expansion. to_expn_id ( ) ,
780769 item. span ,
781770 parent. no_implicit_prelude
782771 || ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
783772 ) ;
784- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
785-
786- if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
787- self . r . mods_with_parse_errors . insert ( def_id) ;
788- }
789-
790- // Descend into the module.
791- self . parent_scope . module = module;
792773 }
793774
794775 // These items live in the value namespace.
@@ -811,15 +792,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
811792 }
812793
813794 ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
814- let module = self . r . new_module (
795+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
796+
797+ self . parent_scope . module = self . r . new_module (
815798 Some ( parent) ,
816799 ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
817800 expansion. to_expn_id ( ) ,
818801 item. span ,
819802 parent. no_implicit_prelude ,
820803 ) ;
821- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
822- self . parent_scope . module = module;
823804 }
824805
825806 // These items live in both the type and value namespaces.
@@ -927,8 +908,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
927908 }
928909 . map ( |module| {
929910 let used = self . process_macro_use_imports ( item, module) ;
911+ let res = module. res ( ) . unwrap ( ) ;
930912 let vis = ty:: Visibility :: < LocalDefId > :: Public ;
931- let binding = ( module , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
913+ let binding = ( res , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
932914 ( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
933915 } )
934916 . unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments