@@ -1026,7 +1026,13 @@ impl<'a> LookupContext<'a> {
1026
1026
fn consider_candidates ( & self , rcvr_ty : ty:: t ,
1027
1027
candidates : & [ Candidate ] )
1028
1028
-> Option < MethodCallee > {
1029
- let relevant_candidates = self . filter_candidates ( rcvr_ty, candidates) ;
1029
+ // FIXME(pcwalton): Do we need to clone here?
1030
+ let relevant_candidates: Vec < Candidate > =
1031
+ candidates. iter ( ) . map ( |c| ( * c) . clone ( ) ) .
1032
+ filter ( |c| self . is_relevant ( rcvr_ty, c) ) . collect ( ) ;
1033
+
1034
+ let relevant_candidates =
1035
+ self . merge_candidates ( relevant_candidates. as_slice ( ) ) ;
1030
1036
1031
1037
if relevant_candidates. len ( ) == 0 {
1032
1038
return None ;
@@ -1063,16 +1069,22 @@ impl<'a> LookupContext<'a> {
1063
1069
Some ( self . confirm_candidate ( rcvr_ty, relevant_candidates. get ( 0 ) ) )
1064
1070
}
1065
1071
1066
- fn filter_candidates ( & self , rcvr_ty : ty:: t , candidates : & [ Candidate ] ) -> Vec < Candidate > {
1067
- let mut relevant_candidates: Vec < Candidate > = Vec :: new ( ) ;
1072
+ fn merge_candidates ( & self , candidates : & [ Candidate ] ) -> Vec < Candidate > {
1073
+ let mut merged = Vec :: new ( ) ;
1074
+ let mut i = 0 ;
1075
+ while i < candidates. len ( ) {
1076
+ let candidate_a = & candidates[ i] ;
1077
+
1078
+ let mut skip = false ;
1068
1079
1069
- for candidate_a in candidates . iter ( ) . filter ( | & c| self . is_relevant ( rcvr_ty , c ) ) {
1070
- // Skip this one if we already have one like it
1071
- if !relevant_candidates . iter ( ) . any ( | candidate_b| {
1080
+ let mut j = i + 1 ;
1081
+ while j < candidates . len ( ) {
1082
+ let candidate_b = & candidates [ j ] ;
1072
1083
debug ! ( "attempting to merge {} and {}" ,
1073
1084
candidate_a. repr( self . tcx( ) ) ,
1074
1085
candidate_b. repr( self . tcx( ) ) ) ;
1075
- match ( & candidate_a. origin , & candidate_b. origin ) {
1086
+ let candidates_same = match ( & candidate_a. origin ,
1087
+ & candidate_b. origin ) {
1076
1088
( & MethodParam ( ref p1) , & MethodParam ( ref p2) ) => {
1077
1089
let same_trait = p1. trait_id == p2. trait_id ;
1078
1090
let same_method = p1. method_num == p2. method_num ;
@@ -1083,13 +1095,25 @@ impl<'a> LookupContext<'a> {
1083
1095
same_trait && same_method && same_param
1084
1096
}
1085
1097
_ => false
1098
+ } ;
1099
+ if candidates_same {
1100
+ skip = true ;
1101
+ break ;
1086
1102
}
1087
- } ) {
1088
- relevant_candidates. push ( candidate_a. clone ( ) ) ;
1103
+ j += 1 ;
1104
+ }
1105
+
1106
+ i += 1 ;
1107
+
1108
+ if skip {
1109
+ // There are more than one of these and we need only one
1110
+ continue ;
1111
+ } else {
1112
+ merged. push ( candidate_a. clone ( ) ) ;
1089
1113
}
1090
1114
}
1091
1115
1092
- relevant_candidates
1116
+ return merged ;
1093
1117
}
1094
1118
1095
1119
fn confirm_candidate ( & self , rcvr_ty : ty:: t , candidate : & Candidate )
0 commit comments