@@ -585,6 +585,10 @@ struct ModuleData<'ra> {
585
585
span : Span ,
586
586
587
587
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 > > ,
588
592
}
589
593
590
594
/// All modules are unique and allocated on a same arena,
@@ -613,6 +617,7 @@ impl<'ra> ModuleData<'ra> {
613
617
expansion : ExpnId ,
614
618
span : Span ,
615
619
no_implicit_prelude : bool ,
620
+ self_binding : Option < NameBinding < ' ra > > ,
616
621
) -> Self {
617
622
let is_foreign = match kind {
618
623
ModuleKind :: Def ( _, def_id, _) => !def_id. is_local ( ) ,
@@ -630,6 +635,7 @@ impl<'ra> ModuleData<'ra> {
630
635
traits : RefCell :: new ( None ) ,
631
636
span,
632
637
expansion,
638
+ self_binding,
633
639
}
634
640
}
635
641
}
@@ -1094,10 +1100,6 @@ pub struct Resolver<'ra, 'tcx> {
1094
1100
builtin_types_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
1095
1101
builtin_attrs_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
1096
1102
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
-
1101
1103
used_extern_options : FxHashSet < Symbol > ,
1102
1104
macro_names : FxHashSet < Ident > ,
1103
1105
builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
@@ -1257,24 +1259,27 @@ impl<'ra> ResolverArenas<'ra> {
1257
1259
span : Span ,
1258
1260
no_implicit_prelude : bool ,
1259
1261
module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1260
- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1261
1262
) -> 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
+ } ;
1262
1270
let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
1263
1271
parent,
1264
1272
kind,
1265
1273
expn_id,
1266
1274
span,
1267
1275
no_implicit_prelude,
1276
+ self_binding,
1268
1277
) ) ) ) ;
1269
- let def_id = module. opt_def_id ( ) ;
1270
1278
if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
1271
1279
self . local_modules . borrow_mut ( ) . push ( module) ;
1272
1280
}
1273
1281
if let Some ( def_id) = def_id {
1274
1282
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) ;
1278
1283
}
1279
1284
module
1280
1285
}
@@ -1417,15 +1422,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1417
1422
) -> Resolver < ' ra , ' tcx > {
1418
1423
let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
1419
1424
let mut module_map = FxIndexMap :: default ( ) ;
1420
- let mut module_self_bindings = FxHashMap :: default ( ) ;
1421
1425
let graph_root = arenas. new_module (
1422
1426
None ,
1423
1427
ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1424
1428
ExpnId :: root ( ) ,
1425
1429
crate_span,
1426
1430
attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
1427
1431
& mut module_map,
1428
- & mut module_self_bindings,
1429
1432
) ;
1430
1433
let empty_module = arenas. new_module (
1431
1434
None ,
@@ -1434,7 +1437,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1434
1437
DUMMY_SP ,
1435
1438
true ,
1436
1439
& mut Default :: default ( ) ,
1437
- & mut Default :: default ( ) ,
1438
1440
) ;
1439
1441
1440
1442
let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1537,8 +1539,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1537
1539
( * ident, binding)
1538
1540
} )
1539
1541
. collect ( ) ,
1540
- module_self_bindings,
1541
-
1542
1542
used_extern_options : Default :: default ( ) ,
1543
1543
macro_names : FxHashSet :: default ( ) ,
1544
1544
builtin_macros : Default :: default ( ) ,
@@ -1610,16 +1610,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1610
1610
no_implicit_prelude : bool ,
1611
1611
) -> Module < ' ra > {
1612
1612
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)
1623
1614
}
1624
1615
1625
1616
fn new_local_macro ( & mut self , def_id : LocalDefId , macro_data : MacroData ) -> & ' ra MacroData {
0 commit comments