@@ -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
}
@@ -1101,10 +1107,6 @@ pub struct Resolver<'ra, 'tcx> {
1101
1107
builtin_types_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
1102
1108
builtin_attrs_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
1103
1109
registered_tool_bindings : FxHashMap < Ident , NameBinding < ' ra > > ,
1104
- /// Binding for implicitly declared names that come with a module,
1105
- /// like `self` (not yet used), or `crate`/`$crate` (for root modules).
1106
- module_self_bindings : FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1107
-
1108
1110
used_extern_options : FxHashSet < Symbol > ,
1109
1111
macro_names : FxHashSet < Ident > ,
1110
1112
builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
@@ -1264,24 +1266,27 @@ impl<'ra> ResolverArenas<'ra> {
1264
1266
span : Span ,
1265
1267
no_implicit_prelude : bool ,
1266
1268
module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1267
- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1268
1269
) -> Module < ' ra > {
1270
+ let ( def_id, self_binding) = match kind {
1271
+ ModuleKind :: Def ( def_kind, def_id, _) => (
1272
+ Some ( def_id) ,
1273
+ Some ( self . new_pub_res_binding ( Res :: Def ( def_kind, def_id) , span, LocalExpnId :: ROOT ) ) ,
1274
+ ) ,
1275
+ ModuleKind :: Block => ( None , None ) ,
1276
+ } ;
1269
1277
let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
1270
1278
parent,
1271
1279
kind,
1272
1280
expn_id,
1273
1281
span,
1274
1282
no_implicit_prelude,
1283
+ self_binding,
1275
1284
) ) ) ) ;
1276
- let def_id = module. opt_def_id ( ) ;
1277
1285
if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
1278
1286
self . local_modules . borrow_mut ( ) . push ( module) ;
1279
1287
}
1280
1288
if let Some ( def_id) = def_id {
1281
1289
module_map. insert ( def_id, module) ;
1282
- let res = module. res ( ) . unwrap ( ) ;
1283
- let binding = self . new_pub_res_binding ( res, module. span , LocalExpnId :: ROOT ) ;
1284
- module_self_bindings. insert ( module, binding) ;
1285
1290
}
1286
1291
module
1287
1292
}
@@ -1424,15 +1429,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1424
1429
) -> Resolver < ' ra , ' tcx > {
1425
1430
let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
1426
1431
let mut module_map = FxIndexMap :: default ( ) ;
1427
- let mut module_self_bindings = FxHashMap :: default ( ) ;
1428
1432
let graph_root = arenas. new_module (
1429
1433
None ,
1430
1434
ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1431
1435
ExpnId :: root ( ) ,
1432
1436
crate_span,
1433
1437
attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
1434
1438
& mut module_map,
1435
- & mut module_self_bindings,
1436
1439
) ;
1437
1440
let empty_module = arenas. new_module (
1438
1441
None ,
@@ -1441,7 +1444,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1441
1444
DUMMY_SP ,
1442
1445
true ,
1443
1446
& mut Default :: default ( ) ,
1444
- & mut Default :: default ( ) ,
1445
1447
) ;
1446
1448
1447
1449
let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1544,8 +1546,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1544
1546
( * ident, binding)
1545
1547
} )
1546
1548
. collect ( ) ,
1547
- module_self_bindings,
1548
-
1549
1549
used_extern_options : Default :: default ( ) ,
1550
1550
macro_names : FxHashSet :: default ( ) ,
1551
1551
builtin_macros : Default :: default ( ) ,
@@ -1617,16 +1617,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1617
1617
no_implicit_prelude : bool ,
1618
1618
) -> Module < ' ra > {
1619
1619
let module_map = & mut self . module_map ;
1620
- let module_self_bindings = & mut self . module_self_bindings ;
1621
- self . arenas . new_module (
1622
- parent,
1623
- kind,
1624
- expn_id,
1625
- span,
1626
- no_implicit_prelude,
1627
- module_map,
1628
- module_self_bindings,
1629
- )
1620
+ self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude, module_map)
1630
1621
}
1631
1622
1632
1623
fn new_local_macro ( & mut self , def_id : LocalDefId , macro_data : MacroData ) -> & ' ra MacroData {
0 commit comments