@@ -871,6 +871,7 @@ enum NameBindingKind<'a> {
871
871
Import {
872
872
binding : & ' a NameBinding < ' a > ,
873
873
directive : & ' a ImportDirective < ' a > ,
874
+ used : Cell < bool > ,
874
875
} ,
875
876
Ambiguity {
876
877
b1 : & ' a NameBinding < ' a > ,
@@ -938,14 +939,6 @@ impl<'a> NameBinding<'a> {
938
939
_ => true ,
939
940
}
940
941
}
941
-
942
- fn ambiguity ( & self ) -> Option < ( & ' a NameBinding < ' a > , & ' a NameBinding < ' a > ) > {
943
- match self . kind {
944
- NameBindingKind :: Ambiguity { b1, b2 } => Some ( ( b1, b2) ) ,
945
- NameBindingKind :: Import { binding, .. } => binding. ambiguity ( ) ,
946
- _ => None ,
947
- }
948
- }
949
942
}
950
943
951
944
/// Interns the names of the primitive types.
@@ -1064,7 +1057,7 @@ pub struct Resolver<'a> {
1064
1057
pub maybe_unused_trait_imports : NodeSet ,
1065
1058
1066
1059
privacy_errors : Vec < PrivacyError < ' a > > ,
1067
- ambiguity_errors : Vec < ( Span , Name , & ' a NameBinding < ' a > ) > ,
1060
+ ambiguity_errors : Vec < ( Span , Name , & ' a NameBinding < ' a > , & ' a NameBinding < ' a > ) > ,
1068
1061
1069
1062
arenas : & ' a ResolverArenas < ' a > ,
1070
1063
dummy_binding : & ' a NameBinding < ' a > ,
@@ -1276,18 +1269,20 @@ impl<'a> Resolver<'a> {
1276
1269
self . used_crates . insert ( krate) ;
1277
1270
}
1278
1271
1279
- if binding. ambiguity ( ) . is_some ( ) {
1280
- self . ambiguity_errors . push ( ( span, name, binding) ) ;
1281
- return true ;
1282
- }
1283
-
1284
- if let NameBindingKind :: Import { directive, binding } = binding. kind {
1285
- self . used_imports . insert ( ( directive. id , ns) ) ;
1286
- self . add_to_glob_map ( directive. id , name) ;
1287
- self . record_use ( name, ns, binding, span) ;
1272
+ match binding. kind {
1273
+ NameBindingKind :: Import { directive, binding, ref used } if !used. get ( ) => {
1274
+ used. set ( true ) ;
1275
+ self . used_imports . insert ( ( directive. id , ns) ) ;
1276
+ self . add_to_glob_map ( directive. id , name) ;
1277
+ self . record_use ( name, ns, binding, span)
1278
+ }
1279
+ NameBindingKind :: Import { .. } => false ,
1280
+ NameBindingKind :: Ambiguity { b1, b2 } => {
1281
+ self . ambiguity_errors . push ( ( span, name, b1, b2) ) ;
1282
+ true
1283
+ }
1284
+ _ => false
1288
1285
}
1289
-
1290
- false
1291
1286
}
1292
1287
1293
1288
fn add_to_glob_map ( & mut self , id : NodeId , name : Name ) {
@@ -3307,9 +3302,8 @@ impl<'a> Resolver<'a> {
3307
3302
fn report_errors ( & self ) {
3308
3303
let mut reported_spans = FnvHashSet ( ) ;
3309
3304
3310
- for & ( span, name, binding ) in & self . ambiguity_errors {
3305
+ for & ( span, name, b1 , b2 ) in & self . ambiguity_errors {
3311
3306
if !reported_spans. insert ( span) { continue }
3312
- let ( b1, b2) = binding. ambiguity ( ) . unwrap ( ) ;
3313
3307
let msg1 = format ! ( "`{}` could resolve to the name imported here" , name) ;
3314
3308
let msg2 = format ! ( "`{}` could also resolve to the name imported here" , name) ;
3315
3309
self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
0 commit comments