@@ -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)
@@ -223,12 +208,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
223
208
let expansion = parent_scope. expansion ;
224
209
// Record primary definitions.
225
210
match res {
226
- Res :: Def ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait , def_id) => {
227
- let module = self . expect_module ( def_id) ;
228
- self . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
229
- }
230
211
Res :: Def (
231
- DefKind :: Struct
212
+ DefKind :: Mod
213
+ | DefKind :: Enum
214
+ | DefKind :: Trait
215
+ | DefKind :: Struct
232
216
| DefKind :: Union
233
217
| DefKind :: Variant
234
218
| DefKind :: TyAlias
@@ -766,22 +750,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
766
750
}
767
751
768
752
ItemKind :: Mod ( _, ident, ref mod_kind) => {
769
- let module = self . r . new_module (
753
+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
754
+
755
+ if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
756
+ self . r . mods_with_parse_errors . insert ( def_id) ;
757
+ }
758
+ self . parent_scope . module = self . r . new_module (
770
759
Some ( parent) ,
771
760
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
772
761
expansion. to_expn_id ( ) ,
773
762
item. span ,
774
763
parent. no_implicit_prelude
775
764
|| ast:: attr:: contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
776
765
) ;
777
- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
778
-
779
- if let ast:: ModKind :: Loaded ( _, _, _, Err ( _) ) = mod_kind {
780
- self . r . mods_with_parse_errors . insert ( def_id) ;
781
- }
782
-
783
- // Descend into the module.
784
- self . parent_scope . module = module;
785
766
}
786
767
787
768
// These items live in the value namespace.
@@ -804,15 +785,15 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
804
785
}
805
786
806
787
ItemKind :: Enum ( ident, _, _) | ItemKind :: Trait ( box ast:: Trait { ident, .. } ) => {
807
- let module = self . r . new_module (
788
+ self . r . define ( parent, ident, TypeNS , ( res, vis, sp, expansion) ) ;
789
+
790
+ self . parent_scope . module = self . r . new_module (
808
791
Some ( parent) ,
809
792
ModuleKind :: Def ( def_kind, def_id, Some ( ident. name ) ) ,
810
793
expansion. to_expn_id ( ) ,
811
794
item. span ,
812
795
parent. no_implicit_prelude ,
813
796
) ;
814
- self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
815
- self . parent_scope . module = module;
816
797
}
817
798
818
799
// These items live in both the type and value namespaces.
@@ -920,8 +901,9 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
920
901
}
921
902
. map ( |module| {
922
903
let used = self . process_macro_use_imports ( item, module) ;
904
+ let res = module. res ( ) . unwrap ( ) ;
923
905
let vis = ty:: Visibility :: < LocalDefId > :: Public ;
924
- let binding = ( module , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
906
+ let binding = ( res , vis, sp, expansion) . to_name_binding ( self . r . arenas ) ;
925
907
( used, Some ( ModuleOrUniformRoot :: Module ( module) ) , binding)
926
908
} )
927
909
. unwrap_or ( ( true , None , self . r . dummy_binding ) ) ;
0 commit comments