@@ -584,6 +584,10 @@ struct ModuleData<'ra> {
584584 span : Span ,
585585
586586 expansion : ExpnId ,
587+
588+ /// Binding for implicitly declared names that come with a module,
589+ /// like `self` (not yet used), or `crate`/`$crate` (for root modules).
590+ self_binding : Option < NameBinding < ' ra > > ,
587591}
588592
589593/// All modules are unique and allocated on a same arena,
@@ -612,6 +616,7 @@ impl<'ra> ModuleData<'ra> {
612616 expansion : ExpnId ,
613617 span : Span ,
614618 no_implicit_prelude : bool ,
619+ self_binding : Option < NameBinding < ' ra > > ,
615620 ) -> Self {
616621 let is_foreign = match kind {
617622 ModuleKind :: Def ( _, def_id, _) => !def_id. is_local ( ) ,
@@ -629,6 +634,7 @@ impl<'ra> ModuleData<'ra> {
629634 traits : RefCell :: new ( None ) ,
630635 span,
631636 expansion,
637+ self_binding,
632638 }
633639 }
634640}
@@ -1093,10 +1099,6 @@ pub struct Resolver<'ra, 'tcx> {
10931099 builtin_types_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
10941100 builtin_attrs_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
10951101 registered_tool_bindings : FxHashMap < Ident , NameBinding < ' ra > > ,
1096- /// Binding for implicitly declared names that come with a module,
1097- /// like `self` (not yet used), or `crate`/`$crate` (for root modules).
1098- module_self_bindings : FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1099-
11001102 used_extern_options : FxHashSet < Symbol > ,
11011103 macro_names : FxHashSet < Ident > ,
11021104 builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
@@ -1253,24 +1255,27 @@ impl<'ra> ResolverArenas<'ra> {
12531255 span : Span ,
12541256 no_implicit_prelude : bool ,
12551257 module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1256- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
12571258 ) -> Module < ' ra > {
1259+ let ( def_id, self_binding) = match kind {
1260+ ModuleKind :: Def ( def_kind, def_id, _) => (
1261+ Some ( def_id) ,
1262+ Some ( self . new_pub_res_binding ( Res :: Def ( def_kind, def_id) , span, LocalExpnId :: ROOT ) ) ,
1263+ ) ,
1264+ ModuleKind :: Block => ( None , None ) ,
1265+ } ;
12581266 let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
12591267 parent,
12601268 kind,
12611269 expn_id,
12621270 span,
12631271 no_implicit_prelude,
1272+ self_binding,
12641273 ) ) ) ) ;
1265- let def_id = module. opt_def_id ( ) ;
12661274 if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
12671275 self . local_modules . borrow_mut ( ) . push ( module) ;
12681276 }
12691277 if let Some ( def_id) = def_id {
12701278 module_map. insert ( def_id, module) ;
1271- let res = module. res ( ) . unwrap ( ) ;
1272- let binding = self . new_pub_res_binding ( res, module. span , LocalExpnId :: ROOT ) ;
1273- module_self_bindings. insert ( module, binding) ;
12741279 }
12751280 module
12761281 }
@@ -1410,15 +1415,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14101415 ) -> Resolver < ' ra , ' tcx > {
14111416 let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
14121417 let mut module_map = FxIndexMap :: default ( ) ;
1413- let mut module_self_bindings = FxHashMap :: default ( ) ;
14141418 let graph_root = arenas. new_module (
14151419 None ,
14161420 ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
14171421 ExpnId :: root ( ) ,
14181422 crate_span,
14191423 attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
14201424 & mut module_map,
1421- & mut module_self_bindings,
14221425 ) ;
14231426 let empty_module = arenas. new_module (
14241427 None ,
@@ -1427,7 +1430,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14271430 DUMMY_SP ,
14281431 true ,
14291432 & mut Default :: default ( ) ,
1430- & mut Default :: default ( ) ,
14311433 ) ;
14321434
14331435 let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1530,8 +1532,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15301532 ( * ident, binding)
15311533 } )
15321534 . collect ( ) ,
1533- module_self_bindings,
1534-
15351535 used_extern_options : Default :: default ( ) ,
15361536 macro_names : FxHashSet :: default ( ) ,
15371537 builtin_macros : Default :: default ( ) ,
@@ -1601,16 +1601,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16011601 no_implicit_prelude : bool ,
16021602 ) -> Module < ' ra > {
16031603 let module_map = & mut self . module_map ;
1604- let module_self_bindings = & mut self . module_self_bindings ;
1605- self . arenas . new_module (
1606- parent,
1607- kind,
1608- expn_id,
1609- span,
1610- no_implicit_prelude,
1611- module_map,
1612- module_self_bindings,
1613- )
1604+ self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude, module_map)
16141605 }
16151606
16161607 fn next_node_id ( & mut self ) -> NodeId {
0 commit comments