@@ -431,7 +431,22 @@ impl ModuleKind {
431431 }
432432}
433433
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 > > > > ;
435450
436451/// One node in the tree of modules.
437452pub struct ModuleData < ' a > {
@@ -491,8 +506,8 @@ impl<'a> ModuleData<'a> {
491506 fn for_each_child < R , F > ( & ' a self , resolver : & mut R , mut f : F )
492507 where R : AsMut < Resolver < ' a > > , F : FnMut ( & mut R , Ident , Namespace , & ' a NameBinding < ' a > )
493508 {
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) ) ;
496511 }
497512 }
498513
@@ -879,6 +894,7 @@ pub struct Resolver<'a> {
879894 module_map : FxHashMap < DefId , Module < ' a > > ,
880895 extern_module_map : FxHashMap < ( DefId , bool /* MacrosOnly? */ ) , Module < ' a > > ,
881896 binding_parent_modules : FxHashMap < PtrKey < ' a , NameBinding < ' a > > , Module < ' a > > ,
897+ underscore_disambiguator : u32 ,
882898
883899 /// Maps glob imports to the names of items actually imported.
884900 pub glob_map : GlobMap ,
@@ -1156,6 +1172,7 @@ impl<'a> Resolver<'a> {
11561172 label_res_map : Default :: default ( ) ,
11571173 export_map : FxHashMap :: default ( ) ,
11581174 trait_map : Default :: default ( ) ,
1175+ underscore_disambiguator : 0 ,
11591176 empty_module,
11601177 module_map,
11611178 block_map : Default :: default ( ) ,
@@ -1280,6 +1297,17 @@ impl<'a> Resolver<'a> {
12801297 self . arenas . alloc_module ( module)
12811298 }
12821299
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+
12831311 fn resolutions ( & mut self , module : Module < ' a > ) -> & ' a Resolutions < ' a > {
12841312 if module. populate_on_access . get ( ) {
12851313 module. populate_on_access . set ( false ) ;
@@ -1288,9 +1316,9 @@ impl<'a> Resolver<'a> {
12881316 & module. lazy_resolutions
12891317 }
12901318
1291- fn resolution ( & mut self , module : Module < ' a > , ident : Ident , ns : Namespace )
1319+ fn resolution ( & mut self , module : Module < ' a > , key : BindingKey )
12921320 -> & ' a RefCell < NameResolution < ' a > > {
1293- * self . resolutions ( module) . borrow_mut ( ) . entry ( ( ident . modern ( ) , ns ) )
1321+ * self . resolutions ( module) . borrow_mut ( ) . entry ( key )
12941322 . or_insert_with ( || self . arenas . alloc_name_resolution ( ) )
12951323 }
12961324
0 commit comments