@@ -1191,6 +1191,7 @@ impl<'a> fmt::Debug for ModuleData<'a> {
11911191#[ derive( Clone , Debug ) ]
11921192pub struct NameBinding < ' a > {
11931193 kind : NameBindingKind < ' a > ,
1194+ ambiguity : Option < ( & ' a NameBinding < ' a > , AmbiguityKind ) > ,
11941195 expansion : Mark ,
11951196 span : Span ,
11961197 vis : ty:: Visibility ,
@@ -1215,11 +1216,6 @@ enum NameBindingKind<'a> {
12151216 directive : & ' a ImportDirective < ' a > ,
12161217 used : Cell < bool > ,
12171218 } ,
1218- Ambiguity {
1219- kind : AmbiguityKind ,
1220- b1 : & ' a NameBinding < ' a > ,
1221- b2 : & ' a NameBinding < ' a > ,
1222- }
12231219}
12241220
12251221struct PrivacyError < ' a > ( Span , Ident , & ' a NameBinding < ' a > ) ;
@@ -1309,15 +1305,13 @@ impl<'a> NameBinding<'a> {
13091305 NameBindingKind :: Def ( def, _) => def,
13101306 NameBindingKind :: Module ( module) => module. def ( ) . unwrap ( ) ,
13111307 NameBindingKind :: Import { binding, .. } => binding. def ( ) ,
1312- NameBindingKind :: Ambiguity { .. } => Def :: Err ,
13131308 }
13141309 }
13151310
1316- fn def_ignoring_ambiguity ( & self ) -> Def {
1317- match self . kind {
1318- NameBindingKind :: Import { binding, .. } => binding. def_ignoring_ambiguity ( ) ,
1319- NameBindingKind :: Ambiguity { b1, .. } => b1. def_ignoring_ambiguity ( ) ,
1320- _ => self . def ( ) ,
1311+ fn is_ambiguity ( & self ) -> bool {
1312+ self . ambiguity . is_some ( ) || match self . kind {
1313+ NameBindingKind :: Import { binding, .. } => binding. is_ambiguity ( ) ,
1314+ _ => false ,
13211315 }
13221316 }
13231317
@@ -1362,7 +1356,6 @@ impl<'a> NameBinding<'a> {
13621356 fn is_glob_import ( & self ) -> bool {
13631357 match self . kind {
13641358 NameBindingKind :: Import { directive, .. } => directive. is_glob ( ) ,
1365- NameBindingKind :: Ambiguity { b1, .. } => b1. is_glob_import ( ) ,
13661359 _ => false ,
13671360 }
13681361 }
@@ -1382,7 +1375,7 @@ impl<'a> NameBinding<'a> {
13821375 }
13831376
13841377 fn macro_kind ( & self ) -> Option < MacroKind > {
1385- match self . def_ignoring_ambiguity ( ) {
1378+ match self . def ( ) {
13861379 Def :: Macro ( _, kind) => Some ( kind) ,
13871380 Def :: NonMacroAttr ( ..) => Some ( MacroKind :: Attr ) ,
13881381 _ => None ,
@@ -1893,6 +1886,7 @@ impl<'a> Resolver<'a> {
18931886 arenas,
18941887 dummy_binding : arenas. alloc_name_binding ( NameBinding {
18951888 kind : NameBindingKind :: Def ( Def :: Err , false ) ,
1889+ ambiguity : None ,
18961890 expansion : Mark :: root ( ) ,
18971891 span : DUMMY_SP ,
18981892 vis : ty:: Visibility :: Public ,
@@ -1963,33 +1957,30 @@ impl<'a> Resolver<'a> {
19631957
19641958 fn record_use ( & mut self , ident : Ident , ns : Namespace ,
19651959 used_binding : & ' a NameBinding < ' a > , is_lexical_scope : bool ) {
1966- match used_binding. kind {
1967- NameBindingKind :: Import { directive, binding, ref used } if !used. get ( ) => {
1968- // Avoid marking `extern crate` items that refer to a name from extern prelude,
1969- // but not introduce it, as used if they are accessed from lexical scope.
1970- if is_lexical_scope {
1971- if let Some ( entry) = self . extern_prelude . get ( & ident. modern ( ) ) {
1972- if let Some ( crate_item) = entry. extern_crate_item {
1973- if ptr:: eq ( used_binding, crate_item) && !entry. introduced_by_item {
1974- return ;
1975- }
1960+ if let Some ( ( b2, kind) ) = used_binding. ambiguity {
1961+ self . ambiguity_errors . push ( AmbiguityError {
1962+ kind, ident, b1 : used_binding, b2,
1963+ misc1 : AmbiguityErrorMisc :: None ,
1964+ misc2 : AmbiguityErrorMisc :: None ,
1965+ } ) ;
1966+ }
1967+ if let NameBindingKind :: Import { directive, binding, ref used } = used_binding. kind {
1968+ // Avoid marking `extern crate` items that refer to a name from extern prelude,
1969+ // but not introduce it, as used if they are accessed from lexical scope.
1970+ if is_lexical_scope {
1971+ if let Some ( entry) = self . extern_prelude . get ( & ident. modern ( ) ) {
1972+ if let Some ( crate_item) = entry. extern_crate_item {
1973+ if ptr:: eq ( used_binding, crate_item) && !entry. introduced_by_item {
1974+ return ;
19761975 }
19771976 }
19781977 }
1979- used. set ( true ) ;
1980- directive. used . set ( true ) ;
1981- self . used_imports . insert ( ( directive. id , ns) ) ;
1982- self . add_to_glob_map ( directive. id , ident) ;
1983- self . record_use ( ident, ns, binding, false ) ;
1984- }
1985- NameBindingKind :: Ambiguity { kind, b1, b2 } => {
1986- self . ambiguity_errors . push ( AmbiguityError {
1987- kind, ident, b1, b2,
1988- misc1 : AmbiguityErrorMisc :: None ,
1989- misc2 : AmbiguityErrorMisc :: None ,
1990- } ) ;
19911978 }
1992- _ => { }
1979+ used. set ( true ) ;
1980+ directive. used . set ( true ) ;
1981+ self . used_imports . insert ( ( directive. id , ns) ) ;
1982+ self . add_to_glob_map ( directive. id , ident) ;
1983+ self . record_use ( ident, ns, binding, false ) ;
19931984 }
19941985 }
19951986
0 commit comments