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