@@ -39,21 +39,6 @@ use crate::{
39
39
40
40
type Res = def:: Res < NodeId > ;
41
41
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
-
57
42
impl < ' ra , Id : Into < DefId > > ToNameBinding < ' ra > for ( Res , ty:: Visibility < Id > , Span , LocalExpnId ) {
58
43
fn to_name_binding ( self , arenas : & ' ra ResolverArenas < ' ra > ) -> NameBinding < ' ra > {
59
44
arenas. alloc_name_binding ( NameBindingData {
@@ -121,7 +106,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
121
106
if !def_id. is_local ( ) {
122
107
// Query `def_kind` is not used because query system overhead is too expensive here.
123
108
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 ( ) {
125
110
let parent = self
126
111
. tcx
127
112
. opt_parent ( def_id)
@@ -221,12 +206,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
221
206
let expansion = parent_scope. expansion ;
222
207
// Record primary definitions.
223
208
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
- }
228
209
Res :: Def (
229
- DefKind :: Struct
210
+ DefKind :: Mod
211
+ | DefKind :: Enum
212
+ | DefKind :: Trait
213
+ | DefKind :: Struct
230
214
| DefKind :: Union
231
215
| DefKind :: Variant
232
216
| DefKind :: TyAlias
@@ -773,22 +757,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
773
757
}
774
758
775
759
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 (
777
766
Some ( parent) ,
778
767
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
779
768
expansion. to_expn_id ( ) ,
780
769
item. span ,
781
770
parent. no_implicit_prelude
782
771
|| ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
783
772
) ;
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;
792
773
}
793
774
794
775
// These items live in the value namespace.
@@ -811,15 +792,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
811
792
}
812
793
813
794
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 (
815
798
Some ( parent) ,
816
799
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
817
800
expansion. to_expn_id ( ) ,
818
801
item. span ,
819
802
parent. no_implicit_prelude ,
820
803
) ;
821
- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
822
- self . parent_scope . module = module;
823
804
}
824
805
825
806
// These items live in both the type and value namespaces.
@@ -927,8 +908,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
927
908
}
928
909
. map ( |module| {
929
910
let used = self . process_macro_use_imports ( item, module) ;
911
+ let res = module. res ( ) . unwrap ( ) ;
930
912
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 ) ;
932
914
( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
933
915
} )
934
916
. unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments