@@ -871,16 +871,23 @@ 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 > ,
877
878
b2 : & ' a NameBinding < ' a > ,
878
879
}
879
880
}
880
881
881
- #[ derive( Clone , Debug ) ]
882
882
struct PrivacyError < ' a > ( Span , Name , & ' a NameBinding < ' a > ) ;
883
883
884
+ struct AmbiguityError < ' a > {
885
+ span : Span ,
886
+ name : Name ,
887
+ b1 : & ' a NameBinding < ' a > ,
888
+ b2 : & ' a NameBinding < ' a > ,
889
+ }
890
+
884
891
impl < ' a > NameBinding < ' a > {
885
892
fn module ( & self ) -> Result < Module < ' a > , bool /* true if an error has already been reported */ > {
886
893
match self . kind {
@@ -938,14 +945,6 @@ impl<'a> NameBinding<'a> {
938
945
_ => true ,
939
946
}
940
947
}
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
948
}
950
949
951
950
/// Interns the names of the primitive types.
@@ -1064,7 +1063,7 @@ pub struct Resolver<'a> {
1064
1063
pub maybe_unused_trait_imports : NodeSet ,
1065
1064
1066
1065
privacy_errors : Vec < PrivacyError < ' a > > ,
1067
- ambiguity_errors : Vec < ( Span , Name , & ' a NameBinding < ' a > ) > ,
1066
+ ambiguity_errors : Vec < AmbiguityError < ' a > > ,
1068
1067
1069
1068
arenas : & ' a ResolverArenas < ' a > ,
1070
1069
dummy_binding : & ' a NameBinding < ' a > ,
@@ -1276,17 +1275,21 @@ impl<'a> Resolver<'a> {
1276
1275
self . used_crates . insert ( krate) ;
1277
1276
}
1278
1277
1279
- if let NameBindingKind :: Import { directive, .. } = binding. kind {
1280
- self . used_imports . insert ( ( directive. id , ns) ) ;
1281
- self . add_to_glob_map ( directive. id , name) ;
1282
- }
1283
-
1284
- if binding. ambiguity ( ) . is_some ( ) {
1285
- self . ambiguity_errors . push ( ( span, name, binding) ) ;
1286
- return true ;
1278
+ match binding. kind {
1279
+ NameBindingKind :: Import { directive, binding, ref used } if !used. get ( ) => {
1280
+ used. set ( true ) ;
1281
+ self . used_imports . insert ( ( directive. id , ns) ) ;
1282
+ self . add_to_glob_map ( directive. id , name) ;
1283
+ self . record_use ( name, ns, binding, span)
1284
+ }
1285
+ NameBindingKind :: Import { .. } => false ,
1286
+ NameBindingKind :: Ambiguity { b1, b2 } => {
1287
+ let ambiguity_error = AmbiguityError { span : span, name : name, b1 : b1, b2 : b2 } ;
1288
+ self . ambiguity_errors . push ( ambiguity_error) ;
1289
+ true
1290
+ }
1291
+ _ => false
1287
1292
}
1288
-
1289
- false
1290
1293
}
1291
1294
1292
1295
fn add_to_glob_map ( & mut self , id : NodeId , name : Name ) {
@@ -3306,9 +3309,8 @@ impl<'a> Resolver<'a> {
3306
3309
fn report_errors ( & self ) {
3307
3310
let mut reported_spans = FnvHashSet ( ) ;
3308
3311
3309
- for & ( span, name, binding ) in & self . ambiguity_errors {
3312
+ for & AmbiguityError { span, name, b1 , b2 } in & self . ambiguity_errors {
3310
3313
if !reported_spans. insert ( span) { continue }
3311
- let ( b1, b2) = binding. ambiguity ( ) . unwrap ( ) ;
3312
3314
let msg1 = format ! ( "`{}` could resolve to the name imported here" , name) ;
3313
3315
let msg2 = format ! ( "`{}` could also resolve to the name imported here" , name) ;
3314
3316
self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
0 commit comments