@@ -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)
@@ -224,12 +209,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
224
209
let expansion = parent_scope. expansion ;
225
210
// Record primary definitions.
226
211
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
- }
231
212
Res :: Def (
232
- DefKind :: Struct
213
+ DefKind :: Mod
214
+ | DefKind :: Enum
215
+ | DefKind :: Trait
216
+ | DefKind :: Struct
233
217
| DefKind :: Union
234
218
| DefKind :: Variant
235
219
| DefKind :: TyAlias
@@ -776,22 +760,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
776
760
}
777
761
778
762
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 (
780
769
Some ( parent) ,
781
770
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
782
771
expansion. to_expn_id ( ) ,
783
772
item. span ,
784
773
parent. no_implicit_prelude
785
774
|| ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
786
775
) ;
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;
795
776
}
796
777
797
778
// These items live in the value namespace.
@@ -814,15 +795,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
814
795
}
815
796
816
797
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 (
818
801
Some ( parent) ,
819
802
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
820
803
expansion. to_expn_id ( ) ,
821
804
item. span ,
822
805
parent. no_implicit_prelude ,
823
806
) ;
824
- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
825
- self . parent_scope . module = module;
826
807
}
827
808
828
809
// These items live in both the type and value namespaces.
@@ -930,8 +911,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
930
911
}
931
912
. map ( |module| {
932
913
let used = self . process_macro_use_imports ( item, module) ;
914
+ let res = module. res ( ) . unwrap ( ) ;
933
915
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 ) ;
935
917
( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
936
918
} )
937
919
. unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments