@@ -871,16 +871,23 @@ enum NameBindingKind<'a> {
871871 Import {
872872 binding : & ' a NameBinding < ' a > ,
873873 directive : & ' a ImportDirective < ' a > ,
874+ used : Cell < bool > ,
874875 } ,
875876 Ambiguity {
876877 b1 : & ' a NameBinding < ' a > ,
877878 b2 : & ' a NameBinding < ' a > ,
878879 }
879880}
880881
881- #[ derive( Clone , Debug ) ]
882882struct PrivacyError < ' a > ( Span , Name , & ' a NameBinding < ' a > ) ;
883883
884+ struct AmbiguityError < ' a > {
885+ span : Span ,
886+ name : Name ,
887+ b1 : & ' a NameBinding < ' a > ,
888+ b2 : & ' a NameBinding < ' a > ,
889+ }
890+
884891impl < ' a > NameBinding < ' a > {
885892 fn module ( & self ) -> Result < Module < ' a > , bool /* true if an error has already been reported */ > {
886893 match self . kind {
@@ -938,14 +945,6 @@ impl<'a> NameBinding<'a> {
938945 _ => true ,
939946 }
940947 }
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- }
949948}
950949
951950/// Interns the names of the primitive types.
@@ -1064,7 +1063,7 @@ pub struct Resolver<'a> {
10641063 pub maybe_unused_trait_imports : NodeSet ,
10651064
10661065 privacy_errors : Vec < PrivacyError < ' a > > ,
1067- ambiguity_errors : Vec < ( Span , Name , & ' a NameBinding < ' a > ) > ,
1066+ ambiguity_errors : Vec < AmbiguityError < ' a > > ,
10681067
10691068 arenas : & ' a ResolverArenas < ' a > ,
10701069 dummy_binding : & ' a NameBinding < ' a > ,
@@ -1276,17 +1275,21 @@ impl<'a> Resolver<'a> {
12761275 self . used_crates . insert ( krate) ;
12771276 }
12781277
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
12871292 }
1288-
1289- false
12901293 }
12911294
12921295 fn add_to_glob_map ( & mut self , id : NodeId , name : Name ) {
@@ -3306,9 +3309,8 @@ impl<'a> Resolver<'a> {
33063309 fn report_errors ( & self ) {
33073310 let mut reported_spans = FnvHashSet ( ) ;
33083311
3309- for & ( span, name, binding ) in & self . ambiguity_errors {
3312+ for & AmbiguityError { span, name, b1 , b2 } in & self . ambiguity_errors {
33103313 if !reported_spans. insert ( span) { continue }
3311- let ( b1, b2) = binding. ambiguity ( ) . unwrap ( ) ;
33123314 let msg1 = format ! ( "`{}` could resolve to the name imported here" , name) ;
33133315 let msg2 = format ! ( "`{}` could also resolve to the name imported here" , name) ;
33143316 self . session . struct_span_err ( span, & format ! ( "`{}` is ambiguous" , name) )
0 commit comments