@@ -519,7 +519,7 @@ struct ModuleData<'a> {
519
519
520
520
/// All modules are unique and allocated on a same arena,
521
521
/// so we can use referential equality to compare them.
522
- #[ derive( Clone , Copy , PartialEq ) ]
522
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
523
523
#[ rustc_pass_by_value]
524
524
struct Module < ' a > ( Interned < ' a , ModuleData < ' a > > ) ;
525
525
@@ -1007,6 +1007,9 @@ pub struct Resolver<'a, 'tcx> {
1007
1007
builtin_types_bindings : FxHashMap < Symbol , NameBinding < ' a > > ,
1008
1008
builtin_attrs_bindings : FxHashMap < Symbol , NameBinding < ' a > > ,
1009
1009
registered_tool_bindings : FxHashMap < Ident , NameBinding < ' a > > ,
1010
+ /// Binding for implicitly declared names that come with a module,
1011
+ /// like `self` (not yet used), or `crate`/`$crate` (for root modules).
1012
+ module_self_bindings : FxHashMap < Module < ' a > , NameBinding < ' a > > ,
1010
1013
1011
1014
used_extern_options : FxHashSet < Symbol > ,
1012
1015
macro_names : FxHashSet < Ident > ,
@@ -1122,6 +1125,7 @@ impl<'a> ResolverArenas<'a> {
1122
1125
span : Span ,
1123
1126
no_implicit_prelude : bool ,
1124
1127
module_map : & mut FxHashMap < DefId , Module < ' a > > ,
1128
+ module_self_bindings : & mut FxHashMap < Module < ' a > , NameBinding < ' a > > ,
1125
1129
) -> Module < ' a > {
1126
1130
let module = Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
1127
1131
parent,
@@ -1136,6 +1140,9 @@ impl<'a> ResolverArenas<'a> {
1136
1140
}
1137
1141
if let Some ( def_id) = def_id {
1138
1142
module_map. insert ( def_id, module) ;
1143
+ let vis = ty:: Visibility :: < DefId > :: Public ;
1144
+ let binding = ( module, vis, module. span , LocalExpnId :: ROOT ) . to_name_binding ( self ) ;
1145
+ module_self_bindings. insert ( module, binding) ;
1139
1146
}
1140
1147
module
1141
1148
}
@@ -1247,13 +1254,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1247
1254
) -> Resolver < ' a , ' tcx > {
1248
1255
let root_def_id = CRATE_DEF_ID . to_def_id ( ) ;
1249
1256
let mut module_map = FxHashMap :: default ( ) ;
1257
+ let mut module_self_bindings = FxHashMap :: default ( ) ;
1250
1258
let graph_root = arenas. new_module (
1251
1259
None ,
1252
1260
ModuleKind :: Def ( DefKind :: Mod , root_def_id, kw:: Empty ) ,
1253
1261
ExpnId :: root ( ) ,
1254
1262
crate_span,
1255
1263
attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
1256
1264
& mut module_map,
1265
+ & mut module_self_bindings,
1257
1266
) ;
1258
1267
let empty_module = arenas. new_module (
1259
1268
None ,
@@ -1262,6 +1271,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1262
1271
DUMMY_SP ,
1263
1272
true ,
1264
1273
& mut FxHashMap :: default ( ) ,
1274
+ & mut FxHashMap :: default ( ) ,
1265
1275
) ;
1266
1276
1267
1277
let mut visibilities = FxHashMap :: default ( ) ;
@@ -1368,6 +1378,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1368
1378
( * ident, binding)
1369
1379
} )
1370
1380
. collect ( ) ,
1381
+ module_self_bindings,
1371
1382
1372
1383
used_extern_options : Default :: default ( ) ,
1373
1384
macro_names : FxHashSet :: default ( ) ,
@@ -1437,7 +1448,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1437
1448
no_implicit_prelude : bool ,
1438
1449
) -> Module < ' a > {
1439
1450
let module_map = & mut self . module_map ;
1440
- self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude, module_map)
1451
+ let module_self_bindings = & mut self . module_self_bindings ;
1452
+ self . arenas . new_module (
1453
+ parent,
1454
+ kind,
1455
+ expn_id,
1456
+ span,
1457
+ no_implicit_prelude,
1458
+ module_map,
1459
+ module_self_bindings,
1460
+ )
1441
1461
}
1442
1462
1443
1463
fn next_node_id ( & mut self ) -> NodeId {
0 commit comments