@@ -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 > ,
@@ -1254,24 +1256,27 @@ impl<'ra> ResolverArenas<'ra> {
1254
1256
span : Span ,
1255
1257
no_implicit_prelude : bool ,
1256
1258
module_map : & mut FxIndexMap < DefId , Module < ' ra > > ,
1257
- module_self_bindings : & mut FxHashMap < Module < ' ra > , NameBinding < ' ra > > ,
1258
1259
) -> 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
+ } ;
1259
1267
let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
1260
1268
parent,
1261
1269
kind,
1262
1270
expn_id,
1263
1271
span,
1264
1272
no_implicit_prelude,
1273
+ self_binding,
1265
1274
) ) ) ) ;
1266
- let def_id = module. opt_def_id ( ) ;
1267
1275
if def_id. is_none_or ( |def_id| def_id. is_local ( ) ) {
1268
1276
self . local_modules . borrow_mut ( ) . push ( module) ;
1269
1277
}
1270
1278
if let Some ( def_id) = def_id {
1271
1279
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) ;
1275
1280
}
1276
1281
module
1277
1282
}
@@ -1411,15 +1416,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1411
1416
) -> Resolver < ' ra , ' tcx > {
1412
1417
let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
1413
1418
let mut module_map = FxIndexMap :: default ( ) ;
1414
- let mut module_self_bindings = FxHashMap :: default ( ) ;
1415
1419
let graph_root = arenas. new_module (
1416
1420
None ,
1417
1421
ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1418
1422
ExpnId :: root ( ) ,
1419
1423
crate_span,
1420
1424
attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
1421
1425
& mut module_map,
1422
- & mut module_self_bindings,
1423
1426
) ;
1424
1427
let empty_module = arenas. new_module (
1425
1428
None ,
@@ -1428,7 +1431,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1428
1431
DUMMY_SP ,
1429
1432
true ,
1430
1433
& mut Default :: default ( ) ,
1431
- & mut Default :: default ( ) ,
1432
1434
) ;
1433
1435
1434
1436
let mut node_id_to_def_id = NodeMap :: default ( ) ;
@@ -1531,8 +1533,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1531
1533
( * ident, binding)
1532
1534
} )
1533
1535
. collect ( ) ,
1534
- module_self_bindings,
1535
-
1536
1536
used_extern_options : Default :: default ( ) ,
1537
1537
macro_names : FxHashSet :: default ( ) ,
1538
1538
builtin_macros : Default :: default ( ) ,
@@ -1602,16 +1602,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1602
1602
no_implicit_prelude : bool ,
1603
1603
) -> Module < ' ra > {
1604
1604
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)
1615
1606
}
1616
1607
1617
1608
fn next_node_id ( & mut self ) -> NodeId {
0 commit comments