@@ -1191,6 +1191,7 @@ impl<'a> fmt::Debug for ModuleData<'a> {
1191
1191
#[ derive( Clone , Debug ) ]
1192
1192
pub struct NameBinding < ' a > {
1193
1193
kind : NameBindingKind < ' a > ,
1194
+ ambiguity : Option < ( & ' a NameBinding < ' a > , AmbiguityKind ) > ,
1194
1195
expansion : Mark ,
1195
1196
span : Span ,
1196
1197
vis : ty:: Visibility ,
@@ -1215,11 +1216,6 @@ enum NameBindingKind<'a> {
1215
1216
directive : & ' a ImportDirective < ' a > ,
1216
1217
used : Cell < bool > ,
1217
1218
} ,
1218
- Ambiguity {
1219
- kind : AmbiguityKind ,
1220
- b1 : & ' a NameBinding < ' a > ,
1221
- b2 : & ' a NameBinding < ' a > ,
1222
- }
1223
1219
}
1224
1220
1225
1221
struct PrivacyError < ' a > ( Span , Ident , & ' a NameBinding < ' a > ) ;
@@ -1309,15 +1305,13 @@ impl<'a> NameBinding<'a> {
1309
1305
NameBindingKind :: Def ( def, _) => def,
1310
1306
NameBindingKind :: Module ( module) => module. def ( ) . unwrap ( ) ,
1311
1307
NameBindingKind :: Import { binding, .. } => binding. def ( ) ,
1312
- NameBindingKind :: Ambiguity { .. } => Def :: Err ,
1313
1308
}
1314
1309
}
1315
1310
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 ,
1321
1315
}
1322
1316
}
1323
1317
@@ -1362,7 +1356,6 @@ impl<'a> NameBinding<'a> {
1362
1356
fn is_glob_import ( & self ) -> bool {
1363
1357
match self . kind {
1364
1358
NameBindingKind :: Import { directive, .. } => directive. is_glob ( ) ,
1365
- NameBindingKind :: Ambiguity { b1, .. } => b1. is_glob_import ( ) ,
1366
1359
_ => false ,
1367
1360
}
1368
1361
}
@@ -1382,7 +1375,7 @@ impl<'a> NameBinding<'a> {
1382
1375
}
1383
1376
1384
1377
fn macro_kind ( & self ) -> Option < MacroKind > {
1385
- match self . def_ignoring_ambiguity ( ) {
1378
+ match self . def ( ) {
1386
1379
Def :: Macro ( _, kind) => Some ( kind) ,
1387
1380
Def :: NonMacroAttr ( ..) => Some ( MacroKind :: Attr ) ,
1388
1381
_ => None ,
@@ -1893,6 +1886,7 @@ impl<'a> Resolver<'a> {
1893
1886
arenas,
1894
1887
dummy_binding : arenas. alloc_name_binding ( NameBinding {
1895
1888
kind : NameBindingKind :: Def ( Def :: Err , false ) ,
1889
+ ambiguity : None ,
1896
1890
expansion : Mark :: root ( ) ,
1897
1891
span : DUMMY_SP ,
1898
1892
vis : ty:: Visibility :: Public ,
@@ -1963,33 +1957,30 @@ impl<'a> Resolver<'a> {
1963
1957
1964
1958
fn record_use ( & mut self , ident : Ident , ns : Namespace ,
1965
1959
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 ;
1976
1975
}
1977
1976
}
1978
1977
}
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
- } ) ;
1991
1978
}
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 ) ;
1993
1984
}
1994
1985
}
1995
1986
0 commit comments