@@ -432,7 +432,22 @@ impl ModuleKind {
432432 }
433433}
434434
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 > > > > ;
436451
437452/// One node in the tree of modules.
438453pub struct ModuleData < ' a > {
@@ -492,8 +507,8 @@ impl<'a> ModuleData<'a> {
492507 fn for_each_child < R , F > ( & ' a self , resolver : & mut R , mut f : F )
493508 where R : AsMut < Resolver < ' a > > , F : FnMut ( & mut R , Ident , Namespace , & ' a NameBinding < ' a > )
494509 {
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) ) ;
497512 }
498513 }
499514
@@ -882,6 +897,7 @@ pub struct Resolver<'a> {
882897 module_map : FxHashMap < DefId , Module < ' a > > ,
883898 extern_module_map : FxHashMap < DefId , Module < ' a > > ,
884899 binding_parent_modules : FxHashMap < PtrKey < ' a , NameBinding < ' a > > , Module < ' a > > ,
900+ underscore_disambiguator : u32 ,
885901
886902 /// Maps glob imports to the names of items actually imported.
887903 pub glob_map : GlobMap ,
@@ -1160,6 +1176,7 @@ impl<'a> Resolver<'a> {
11601176 extern_crate_map : Default :: default ( ) ,
11611177 export_map : FxHashMap :: default ( ) ,
11621178 trait_map : Default :: default ( ) ,
1179+ underscore_disambiguator : 0 ,
11631180 empty_module,
11641181 module_map,
11651182 block_map : Default :: default ( ) ,
@@ -1284,6 +1301,17 @@ impl<'a> Resolver<'a> {
12841301 self . arenas . alloc_module ( module)
12851302 }
12861303
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+
12871315 fn resolutions ( & mut self , module : Module < ' a > ) -> & ' a Resolutions < ' a > {
12881316 if module. populate_on_access . get ( ) {
12891317 module. populate_on_access . set ( false ) ;
@@ -1292,9 +1320,9 @@ impl<'a> Resolver<'a> {
12921320 & module. lazy_resolutions
12931321 }
12941322
1295- fn resolution ( & mut self , module : Module < ' a > , ident : Ident , ns : Namespace )
1323+ fn resolution ( & mut self , module : Module < ' a > , key : BindingKey )
12961324 -> & ' a RefCell < NameResolution < ' a > > {
1297- * self . resolutions ( module) . borrow_mut ( ) . entry ( ( ident . modern ( ) , ns ) )
1325+ * self . resolutions ( module) . borrow_mut ( ) . entry ( key )
12981326 . or_insert_with ( || self . arenas . alloc_name_resolution ( ) )
12991327 }
13001328
0 commit comments