@@ -9,11 +9,9 @@ use crate::def_collector::collect_definitions;
9
9
use crate :: imports:: { Import , ImportKind } ;
10
10
use crate :: macros:: { MacroRulesBinding , MacroRulesScope , MacroRulesScopeRef } ;
11
11
use crate :: Namespace :: { self , MacroNS , TypeNS , ValueNS } ;
12
- use crate :: { CrateLint , Determinacy , PathResult , ResolutionError , VisResolutionError } ;
13
- use crate :: {
14
- ExternPreludeEntry , ModuleOrUniformRoot , ParentScope , PerNS , Resolver , ResolverArenas ,
15
- } ;
16
- use crate :: { Module , ModuleData , ModuleKind , NameBinding , NameBindingKind , Segment , ToNameBinding } ;
12
+ use crate :: { CrateLint , Determinacy , ExternPreludeEntry , Module , ModuleKind , ModuleOrUniformRoot } ;
13
+ use crate :: { NameBinding , NameBindingKind , ParentScope , PathResult , PerNS , ResolutionError } ;
14
+ use crate :: { Resolver , ResolverArenas , Segment , ToNameBinding , VisResolutionError } ;
17
15
18
16
use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
19
17
use rustc_ast:: { self as ast, AssocItem , AssocItemKind , MetaItemKind , StmtKind } ;
@@ -142,13 +140,14 @@ impl<'a> Resolver<'a> {
142
140
} ;
143
141
144
142
// Allocate and return a new module with the information we found
145
- let kind = ModuleKind :: Def ( DefKind :: Mod , def_id, name) ;
146
- let module = self . arenas . alloc_module ( ModuleData :: new (
143
+ let module = self . arenas . new_module (
147
144
parent,
148
- kind ,
145
+ ModuleKind :: Def ( DefKind :: Mod , def_id , name ) ,
149
146
self . cstore ( ) . module_expansion_untracked ( def_id, & self . session ) ,
150
147
self . cstore ( ) . get_span_untracked ( def_id, & self . session ) ,
151
- ) ) ;
148
+ // FIXME: Account for `#[no_implicit_prelude]` attributes.
149
+ parent. map_or ( false , |module| module. no_implicit_prelude ) ,
150
+ ) ;
152
151
self . extern_module_map . insert ( def_id, module) ;
153
152
module
154
153
}
@@ -767,13 +766,14 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
767
766
}
768
767
769
768
ItemKind :: Mod ( ..) => {
770
- let module_kind = ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ;
771
- let module = self . r . arenas . alloc_module ( ModuleData {
772
- no_implicit_prelude : parent. no_implicit_prelude || {
773
- self . r . session . contains_name ( & item. attrs , sym:: no_implicit_prelude)
774
- } ,
775
- ..ModuleData :: new ( Some ( parent) , module_kind, expansion. to_expn_id ( ) , item. span )
776
- } ) ;
769
+ let module = self . r . arenas . new_module (
770
+ Some ( parent) ,
771
+ ModuleKind :: Def ( DefKind :: Mod , def_id, ident. name ) ,
772
+ expansion. to_expn_id ( ) ,
773
+ item. span ,
774
+ parent. no_implicit_prelude
775
+ || self . r . session . contains_name ( & item. attrs , sym:: no_implicit_prelude) ,
776
+ ) ;
777
777
self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
778
778
self . r . module_map . insert ( local_def_id, module) ;
779
779
@@ -806,9 +806,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
806
806
}
807
807
808
808
ItemKind :: Enum ( _, _) => {
809
- let module_kind = ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ;
810
- let module =
811
- self . r . new_module ( parent, module_kind, expansion. to_expn_id ( ) , item. span ) ;
809
+ let module = self . r . arenas . new_module (
810
+ Some ( parent) ,
811
+ ModuleKind :: Def ( DefKind :: Enum , def_id, ident. name ) ,
812
+ expansion. to_expn_id ( ) ,
813
+ item. span ,
814
+ parent. no_implicit_prelude ,
815
+ ) ;
812
816
self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
813
817
self . parent_scope . module = module;
814
818
}
@@ -876,9 +880,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
876
880
877
881
ItemKind :: Trait ( ..) => {
878
882
// Add all the items within to a new module.
879
- let module_kind = ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ;
880
- let module =
881
- self . r . new_module ( parent, module_kind, expansion. to_expn_id ( ) , item. span ) ;
883
+ let module = self . r . arenas . new_module (
884
+ Some ( parent) ,
885
+ ModuleKind :: Def ( DefKind :: Trait , def_id, ident. name ) ,
886
+ expansion. to_expn_id ( ) ,
887
+ item. span ,
888
+ parent. no_implicit_prelude ,
889
+ ) ;
882
890
self . r . define ( parent, ident, TypeNS , ( module, vis, sp, expansion) ) ;
883
891
self . parent_scope . module = module;
884
892
}
@@ -915,11 +923,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
915
923
let parent = self . parent_scope . module ;
916
924
let expansion = self . parent_scope . expansion ;
917
925
if self . block_needs_anonymous_module ( block) {
918
- let module = self . r . new_module (
919
- parent,
926
+ let module = self . r . arenas . new_module (
927
+ Some ( parent) ,
920
928
ModuleKind :: Block ( block. id ) ,
921
929
expansion. to_expn_id ( ) ,
922
930
block. span ,
931
+ parent. no_implicit_prelude ,
923
932
) ;
924
933
self . r . block_map . insert ( block. id , module) ;
925
934
self . parent_scope . module = module; // Descend into the block.
@@ -935,11 +944,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
935
944
// Record primary definitions.
936
945
match res {
937
946
Res :: Def ( kind @ ( DefKind :: Mod | DefKind :: Enum | DefKind :: Trait ) , def_id) => {
938
- let module = self . r . new_module (
939
- parent,
947
+ let module = self . r . arenas . new_module (
948
+ Some ( parent) ,
940
949
ModuleKind :: Def ( kind, def_id, ident. name ) ,
941
950
expansion. to_expn_id ( ) ,
942
951
span,
952
+ // FIXME: Account for `#[no_implicit_prelude]` attributes.
953
+ parent. no_implicit_prelude ,
943
954
) ;
944
955
self . r . define ( parent, ident, TypeNS , ( module, vis, span, expansion) ) ;
945
956
}
0 commit comments