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