@@ -585,6 +585,10 @@ struct ModuleData<'ra> {
585585 span : Span ,
586586
587587 expansion : ExpnId ,
588+
589+ /// Binding for implicitly declared names that come with a module,
590+ /// like `self` (not yet used), or `crate`/`$crate` (for root modules).
591+ self_binding : Option < NameBinding < ' ra > > ,
588592}
589593
590594/// All modules are unique and allocated on a same arena,
@@ -613,6 +617,7 @@ impl<'ra> ModuleData<'ra> {
613617 expansion : ExpnId ,
614618 span : Span ,
615619 no_implicit_prelude : bool ,
620+ self_binding : Option < NameBinding < ' ra > > ,
616621 ) -> Self {
617622 let is_foreign = match kind {
618623 ModuleKind :: Def ( _, def_id, _) => !def_id. is_local ( ) ,
@@ -630,6 +635,7 @@ impl<'ra> ModuleData<'ra> {
630635 traits : RefCell :: new ( None ) ,
631636 span,
632637 expansion,
638+ self_binding,
633639 }
634640 }
635641}
@@ -1094,10 +1100,6 @@ pub struct Resolver<'ra, 'tcx> {
10941100 builtin_types_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
10951101 builtin_attrs_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
10961102 registered_tool_bindings : FxHashMap < Ident , NameBinding < ' ra > > ,
1097- /// Binding for implicitly declared names that come with a module,
1098- /// like `self` (not yet used), or `crate`/`$crate` (for root modules).
1099- module_self_bindings : FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1100-
11011103 used_extern_options : FxHashSet < Symbol > ,
11021104 macro_names : FxHashSet < Ident > ,
11031105 builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
@@ -1254,24 +1256,27 @@ impl<'ra> ResolverArenas<'ra> {
12541256 span : Span ,
12551257 no_implicit_prelude : bool ,
12561258 module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1257- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
12581259 ) -> Module < ' ra > {
1260+ let ( def_id, self_binding) = match kind {
1261+ ModuleKind :: Def ( def_kind, def_id, _) => (
1262+ Some ( def_id) ,
1263+ Some ( self . new_pub_res_binding ( Res :: Def ( def_kind, def_id) , span, LocalExpnId :: ROOT ) ) ,
1264+ ) ,
1265+ ModuleKind :: Block => ( None , None ) ,
1266+ } ;
12591267 let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
12601268 parent,
12611269 kind,
12621270 expn_id,
12631271 span,
12641272 no_implicit_prelude,
1273+ self_binding,
12651274 ) ) ) ) ;
1266- let def_id = module. opt_def_id ( ) ;
12671275 if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
12681276 self . local_modules . borrow_mut ( ) . push ( module) ;
12691277 }
12701278 if let Some ( def_id) = def_id {
12711279 module_map. insert ( def_id, module) ;
1272- let res = module. res ( ) . unwrap ( ) ;
1273- let binding = self . new_pub_res_binding ( res, module. span , LocalExpnId :: ROOT ) ;
1274- module_self_bindings. insert ( module, binding) ;
12751280 }
12761281 module
12771282 }
@@ -1411,15 +1416,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14111416 ) -> Resolver < ' ra , ' tcx > {
14121417 let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
14131418 let mut module_map = FxIndexMap :: default ( ) ;
1414- let mut module_self_bindings = FxHashMap :: default ( ) ;
14151419 let graph_root = arenas. new_module (
14161420 None ,
14171421 ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
14181422 ExpnId :: root ( ) ,
14191423 crate_span,
14201424 attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
14211425 & mut module_map,
1422- & mut module_self_bindings,
14231426 ) ;
14241427 let empty_module = arenas. new_module (
14251428 None ,
@@ -1428,7 +1431,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14281431 DUMMY_SP ,
14291432 true ,
14301433 & mut Default :: default ( ) ,
1431- & mut Default :: default ( ) ,
14321434 ) ;
14331435
14341436 let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1531,8 +1533,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15311533 ( * ident, binding)
15321534 } )
15331535 . collect ( ) ,
1534- module_self_bindings,
1535-
15361536 used_extern_options : Default :: default ( ) ,
15371537 macro_names : FxHashSet :: default ( ) ,
15381538 builtin_macros : Default :: default ( ) ,
@@ -1602,16 +1602,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16021602 no_implicit_prelude : bool ,
16031603 ) -> Module < ' ra > {
16041604 let module_map = & mut self . module_map ;
1605- let module_self_bindings = & mut self . module_self_bindings ;
1606- self . arenas . new_module (
1607- parent,
1608- kind,
1609- expn_id,
1610- span,
1611- no_implicit_prelude,
1612- module_map,
1613- module_self_bindings,
1614- )
1605+ self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude, module_map)
16151606 }
16161607
16171608 fn next_node_id ( & mut self ) -> NodeId {
0 commit comments