@@ -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 > ,
@@ -1257,24 +1259,27 @@ impl<'ra> ResolverArenas<'ra> {
12571259 span : Span ,
12581260 no_implicit_prelude : bool ,
12591261 module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1260- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
12611262 ) -> Module < ' ra > {
1263+ let ( def_id, self_binding) = match kind {
1264+ ModuleKind :: Def ( def_kind, def_id, _) => (
1265+ Some ( def_id) ,
1266+ Some ( self . new_pub_res_binding ( Res :: Def ( def_kind, def_id) , span, LocalExpnId :: ROOT ) ) ,
1267+ ) ,
1268+ ModuleKind :: Block => ( None , None ) ,
1269+ } ;
12621270 let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
12631271 parent,
12641272 kind,
12651273 expn_id,
12661274 span,
12671275 no_implicit_prelude,
1276+ self_binding,
12681277 ) ) ) ) ;
1269- let def_id = module. opt_def_id ( ) ;
12701278 if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
12711279 self . local_modules . borrow_mut ( ) . push ( module) ;
12721280 }
12731281 if let Some ( def_id) = def_id {
12741282 module_map. insert ( def_id, module) ;
1275- let res = module. res ( ) . unwrap ( ) ;
1276- let binding = self . new_pub_res_binding ( res, module. span , LocalExpnId :: ROOT ) ;
1277- module_self_bindings. insert ( module, binding) ;
12781283 }
12791284 module
12801285 }
@@ -1417,15 +1422,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14171422 ) -> Resolver < ' ra , ' tcx > {
14181423 let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
14191424 let mut module_map = FxIndexMap :: default ( ) ;
1420- let mut module_self_bindings = FxHashMap :: default ( ) ;
14211425 let graph_root = arenas. new_module (
14221426 None ,
14231427 ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
14241428 ExpnId :: root ( ) ,
14251429 crate_span,
14261430 attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
14271431 & mut module_map,
1428- & mut module_self_bindings,
14291432 ) ;
14301433 let empty_module = arenas. new_module (
14311434 None ,
@@ -1434,7 +1437,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14341437 DUMMY_SP ,
14351438 true ,
14361439 & mut Default :: default ( ) ,
1437- & mut Default :: default ( ) ,
14381440 ) ;
14391441
14401442 let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1537,8 +1539,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15371539 ( * ident, binding)
15381540 } )
15391541 . collect ( ) ,
1540- module_self_bindings,
1541-
15421542 used_extern_options : Default :: default ( ) ,
15431543 macro_names : FxHashSet :: default ( ) ,
15441544 builtin_macros : Default :: default ( ) ,
@@ -1610,16 +1610,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16101610 no_implicit_prelude : bool ,
16111611 ) -> Module < ' ra > {
16121612 let module_map = & mut self . module_map ;
1613- let module_self_bindings = & mut self . module_self_bindings ;
1614- self . arenas . new_module (
1615- parent,
1616- kind,
1617- expn_id,
1618- span,
1619- no_implicit_prelude,
1620- module_map,
1621- module_self_bindings,
1622- )
1613+ self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude, module_map)
16231614 }
16241615
16251616 fn new_local_macro ( & mut self , def_id : LocalDefId , macro_data : MacroData ) -> & ' ra MacroData {
0 commit comments