@@ -584,6 +584,10 @@ struct ModuleData<'ra> {
584
584
span : Span ,
585
585
586
586
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 > > ,
587
591
}
588
592
589
593
/// All modules are unique and allocated on a same arena,
@@ -612,6 +616,7 @@ impl<'ra> ModuleData<'ra> {
612
616
expansion : ExpnId ,
613
617
span : Span ,
614
618
no_implicit_prelude : bool ,
619
+ self_binding : Option < NameBinding < ' ra > > ,
615
620
) -> Self {
616
621
let is_foreign = match kind {
617
622
ModuleKind :: Def ( _, def_id, _) => !def_id. is_local ( ) ,
@@ -629,6 +634,7 @@ impl<'ra> ModuleData<'ra> {
629
634
traits : RefCell :: new ( None ) ,
630
635
span,
631
636
expansion,
637
+ self_binding,
632
638
}
633
639
}
634
640
}
@@ -1093,10 +1099,6 @@ pub struct Resolver<'ra, 'tcx> {
1093
1099
builtin_types_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
1094
1100
builtin_attrs_bindings : FxHashMap < Symbol , NameBinding < ' ra > > ,
1095
1101
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
-
1100
1102
used_extern_options : FxHashSet < Symbol > ,
1101
1103
macro_names : FxHashSet < Ident > ,
1102
1104
builtin_macros : FxHashMap < Symbol , SyntaxExtensionKind > ,
@@ -1253,24 +1255,27 @@ impl<'ra> ResolverArenas<'ra> {
1253
1255
span : Span ,
1254
1256
no_implicit_prelude : bool ,
1255
1257
module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1256
- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1257
1258
) -> 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
+ } ;
1258
1266
let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
1259
1267
parent,
1260
1268
kind,
1261
1269
expn_id,
1262
1270
span,
1263
1271
no_implicit_prelude,
1272
+ self_binding,
1264
1273
) ) ) ) ;
1265
- let def_id = module. opt_def_id ( ) ;
1266
1274
if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
1267
1275
self . local_modules . borrow_mut ( ) . push ( module) ;
1268
1276
}
1269
1277
if let Some ( def_id) = def_id {
1270
1278
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) ;
1274
1279
}
1275
1280
module
1276
1281
}
@@ -1410,15 +1415,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1410
1415
) -> Resolver < ' ra , ' tcx > {
1411
1416
let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
1412
1417
let mut module_map = FxIndexMap :: default ( ) ;
1413
- let mut module_self_bindings = FxHashMap :: default ( ) ;
1414
1418
let graph_root = arenas. new_module (
1415
1419
None ,
1416
1420
ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1417
1421
ExpnId :: root ( ) ,
1418
1422
crate_span,
1419
1423
attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
1420
1424
& mut module_map,
1421
- & mut module_self_bindings,
1422
1425
) ;
1423
1426
let empty_module = arenas. new_module (
1424
1427
None ,
@@ -1427,7 +1430,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1427
1430
DUMMY_SP ,
1428
1431
true ,
1429
1432
& mut Default :: default ( ) ,
1430
- & mut Default :: default ( ) ,
1431
1433
) ;
1432
1434
1433
1435
let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1530,8 +1532,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1530
1532
( * ident, binding)
1531
1533
} )
1532
1534
. collect ( ) ,
1533
- module_self_bindings,
1534
-
1535
1535
used_extern_options : Default :: default ( ) ,
1536
1536
macro_names : FxHashSet :: default ( ) ,
1537
1537
builtin_macros : Default :: default ( ) ,
@@ -1601,16 +1601,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1601
1601
no_implicit_prelude : bool ,
1602
1602
) -> Module < ' ra > {
1603
1603
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)
1614
1605
}
1615
1606
1616
1607
fn next_node_id ( & mut self ) -> NodeId {
0 commit comments