@@ -431,7 +431,22 @@ impl ModuleKind {
431
431
}
432
432
}
433
433
434
- type Resolutions < ' a > = RefCell < FxIndexMap < ( Ident , Namespace ) , & ' a RefCell < NameResolution < ' a > > > > ;
434
+ /// A key that identifies a binding in a given `Module`.
435
+ ///
436
+ /// Multiple bindings in the same module can have the same key (in a valid
437
+ /// program) if all but one of them come from glob imports.
438
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash ) ]
439
+ struct BindingKey {
440
+ /// The identifier for the binding, aways the `modern` version of the
441
+ /// identifier.
442
+ ident : Ident ,
443
+ ns : Namespace ,
444
+ /// 0 if ident is not `_`, otherwise a value that's unique to the specific
445
+ /// `_` in the expanded AST that introduced this binding.
446
+ disambiguator : u32 ,
447
+ }
448
+
449
+ type Resolutions < ' a > = RefCell < FxIndexMap < BindingKey , & ' a RefCell < NameResolution < ' a > > > > ;
435
450
436
451
/// One node in the tree of modules.
437
452
pub struct ModuleData < ' a > {
@@ -491,8 +506,8 @@ impl<'a> ModuleData<'a> {
491
506
fn for_each_child < R , F > ( & ' a self , resolver : & mut R , mut f : F )
492
507
where R : AsMut < Resolver < ' a > > , F : FnMut ( & mut R , Ident , Namespace , & ' a NameBinding < ' a > )
493
508
{
494
- for ( & ( ident , ns ) , name_resolution) in resolver. as_mut ( ) . resolutions ( self ) . borrow ( ) . iter ( ) {
495
- name_resolution. borrow ( ) . binding . map ( |binding| f ( resolver, ident, ns, binding) ) ;
509
+ for ( key , name_resolution) in resolver. as_mut ( ) . resolutions ( self ) . borrow ( ) . iter ( ) {
510
+ name_resolution. borrow ( ) . binding . map ( |binding| f ( resolver, key . ident , key . ns , binding) ) ;
496
511
}
497
512
}
498
513
@@ -879,6 +894,7 @@ pub struct Resolver<'a> {
879
894
module_map : FxHashMap < DefId , Module < ' a > > ,
880
895
extern_module_map : FxHashMap < ( DefId , bool /* MacrosOnly? */ ) , Module < ' a > > ,
881
896
binding_parent_modules : FxHashMap < PtrKey < ' a , NameBinding < ' a > > , Module < ' a > > ,
897
+ underscore_disambiguator : u32 ,
882
898
883
899
/// Maps glob imports to the names of items actually imported.
884
900
pub glob_map : GlobMap ,
@@ -1156,6 +1172,7 @@ impl<'a> Resolver<'a> {
1156
1172
label_res_map : Default :: default ( ) ,
1157
1173
export_map : FxHashMap :: default ( ) ,
1158
1174
trait_map : Default :: default ( ) ,
1175
+ underscore_disambiguator : 0 ,
1159
1176
empty_module,
1160
1177
module_map,
1161
1178
block_map : Default :: default ( ) ,
@@ -1280,6 +1297,17 @@ impl<'a> Resolver<'a> {
1280
1297
self . arenas . alloc_module ( module)
1281
1298
}
1282
1299
1300
+ fn new_key ( & mut self , ident : Ident , ns : Namespace ) -> BindingKey {
1301
+ let ident = ident. modern ( ) ;
1302
+ let disambiguator = if ident. name == kw:: Underscore {
1303
+ self . underscore_disambiguator += 1 ;
1304
+ self . underscore_disambiguator
1305
+ } else {
1306
+ 0
1307
+ } ;
1308
+ BindingKey { ident, ns, disambiguator }
1309
+ }
1310
+
1283
1311
fn resolutions ( & mut self , module : Module < ' a > ) -> & ' a Resolutions < ' a > {
1284
1312
if module. populate_on_access . get ( ) {
1285
1313
module. populate_on_access . set ( false ) ;
@@ -1288,9 +1316,9 @@ impl<'a> Resolver<'a> {
1288
1316
& module. lazy_resolutions
1289
1317
}
1290
1318
1291
- fn resolution ( & mut self , module : Module < ' a > , ident : Ident , ns : Namespace )
1319
+ fn resolution ( & mut self , module : Module < ' a > , key : BindingKey )
1292
1320
-> & ' a RefCell < NameResolution < ' a > > {
1293
- * self . resolutions ( module) . borrow_mut ( ) . entry ( ( ident . modern ( ) , ns ) )
1321
+ * self . resolutions ( module) . borrow_mut ( ) . entry ( key )
1294
1322
. or_insert_with ( || self . arenas . alloc_name_resolution ( ) )
1295
1323
}
1296
1324
0 commit comments