@@ -135,7 +135,7 @@ pub enum PickKind<'tcx> {
135
135
ty:: PolyTraitRef < ' tcx > ) ,
136
136
}
137
137
138
- pub type PickResult < ' tcx > = Result < Vec < Pick < ' tcx > > , MethodError < ' tcx > > ;
138
+ pub type PickResult < ' tcx > = Result < Pick < ' tcx > , MethodError < ' tcx > > ;
139
139
140
140
#[ derive( PartialEq , Eq , Copy , Clone , Debug ) ]
141
141
pub enum Mode {
@@ -175,8 +175,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
175
175
. iter ( )
176
176
. flat_map ( |& method_name| {
177
177
match self . probe_for_name ( span, mode, method_name, self_ty, scope_expr_id) {
178
- Ok ( picks ) => picks . into_iter ( ) . map ( move | pick| pick . item ) . collect ( ) ,
179
- Err ( _) => vec ! [ ] ,
178
+ Ok ( pick ) => Some ( pick. item ) ,
179
+ Err ( _) => None ,
180
180
}
181
181
} )
182
182
. collect ( )
@@ -219,7 +219,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
219
219
// think cause spurious errors. Really though this part should
220
220
// take place in the `self.probe` below.
221
221
let steps = if mode == Mode :: MethodCall {
222
- match self . create_steps ( span, self_ty, & looking_for ) {
222
+ match self . create_steps ( span, self_ty) {
223
223
Some ( steps) => steps,
224
224
None => {
225
225
return Err ( MethodError :: NoMatch ( NoMatchData :: new ( Vec :: new ( ) ,
@@ -272,8 +272,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
272
272
273
273
fn create_steps ( & self ,
274
274
span : Span ,
275
- self_ty : Ty < ' tcx > ,
276
- looking_for : & LookingFor < ' tcx > )
275
+ self_ty : Ty < ' tcx > )
277
276
-> Option < Vec < CandidateStep < ' tcx > > > {
278
277
// FIXME: we don't need to create the entire steps in one pass
279
278
@@ -288,12 +287,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
288
287
} )
289
288
. collect ( ) ;
290
289
291
- let final_ty = match looking_for {
292
- & LookingFor :: MethodName ( _) => autoderef. unambiguous_final_ty ( ) ,
293
- // Since ReturnType case tries to coerce the returned type to the
294
- // expected one, we need all the information!
295
- & LookingFor :: ReturnType ( _) => self_ty,
296
- } ;
290
+ let final_ty = autoderef. unambiguous_final_ty ( ) ;
297
291
match final_ty. sty {
298
292
ty:: TyArray ( elem_ty, _) => {
299
293
let dereferences = steps. len ( ) - 1 ;
@@ -935,8 +929,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
935
929
LookingFor :: ReturnType ( _) => false ,
936
930
} ) ;
937
931
938
- if let Some ( ret ) = self . pick_core ( ) {
939
- return ret ;
932
+ if let Some ( r ) = self . pick_core ( ) {
933
+ return r ;
940
934
}
941
935
942
936
let static_candidates = mem:: replace ( & mut self . static_candidates , vec ! [ ] ) ;
@@ -956,21 +950,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
956
950
//Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
957
951
Some ( Err ( MethodError :: Ambiguity ( v) ) ) => {
958
952
v. into_iter ( )
959
- . map ( |source| {
960
- match source {
961
- TraitSource ( id) => id,
962
- ImplSource ( impl_id) => {
963
- match tcx. trait_id_of_impl ( impl_id) {
964
- Some ( id) => id,
965
- None => {
966
- span_bug ! ( span,
967
- "found inherent method when looking at traits" )
953
+ . map ( |source| {
954
+ match source {
955
+ TraitSource ( id) => id,
956
+ ImplSource ( impl_id) => {
957
+ match tcx. trait_id_of_impl ( impl_id) {
958
+ Some ( id) => id,
959
+ None => {
960
+ span_bug ! ( span,
961
+ "found inherent method when looking at traits" )
962
+ }
968
963
}
969
964
}
970
965
}
971
- }
972
- } )
973
- . collect ( )
966
+ } )
967
+ . collect ( )
974
968
}
975
969
Some ( Err ( MethodError :: NoMatch ( NoMatchData { out_of_scope_traits : others, .. } ) ) ) => {
976
970
assert ! ( others. is_empty( ) ) ;
@@ -997,9 +991,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
997
991
let steps = self . steps . clone ( ) ;
998
992
999
993
// find the first step that works
1000
- steps. iter ( )
1001
- . filter_map ( |step| self . pick_step ( step) )
1002
- . next ( )
994
+ steps. iter ( ) . filter_map ( |step| self . pick_step ( step) ) . next ( )
1003
995
}
1004
996
1005
997
fn pick_step ( & mut self , step : & CandidateStep < ' tcx > ) -> Option < PickResult < ' tcx > > {
@@ -1030,18 +1022,16 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1030
1022
}
1031
1023
1032
1024
self . pick_method ( step. self_ty ) . map ( |r| {
1033
- r. map ( |mut picks| {
1034
- for pick in picks. iter_mut ( ) {
1035
- pick. autoderefs = step. autoderefs ;
1036
-
1037
- // Insert a `&*` or `&mut *` if this is a reference type:
1038
- if let ty:: TyRef ( _, mt) = step. self_ty . sty {
1039
- pick. autoderefs += 1 ;
1040
- pick. autoref = Some ( mt. mutbl ) ;
1041
- }
1025
+ r. map ( |mut pick| {
1026
+ pick. autoderefs = step. autoderefs ;
1027
+
1028
+ // Insert a `&*` or `&mut *` if this is a reference type:
1029
+ if let ty:: TyRef ( _, mt) = step. self_ty . sty {
1030
+ pick. autoderefs += 1 ;
1031
+ pick. autoref = Some ( mt. mutbl ) ;
1042
1032
}
1043
1033
1044
- picks
1034
+ pick
1045
1035
} )
1046
1036
} )
1047
1037
}
@@ -1054,44 +1044,28 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1054
1044
let region = tcx. mk_region ( ty:: ReErased ) ;
1055
1045
1056
1046
// Search through mutabilities in order to find one where pick works:
1057
- let mut elements = [ hir:: MutImmutable , hir:: MutMutable ] ;
1058
- let mut it = elements
1059
- . iter_mut ( )
1060
- . filter_map ( |& mut m| {
1047
+ [ hir:: MutImmutable , hir:: MutMutable ]
1048
+ . iter ( )
1049
+ . filter_map ( |& m| {
1061
1050
let autoref_ty = tcx. mk_ref ( region,
1062
1051
ty:: TypeAndMut {
1063
1052
ty : step. self_ty ,
1064
1053
mutbl : m,
1065
1054
} ) ;
1066
1055
self . pick_method ( autoref_ty) . map ( |r| {
1067
- r. map ( |mut picks| {
1068
- for pick in picks. iter_mut ( ) {
1069
- pick. autoderefs = step. autoderefs ;
1070
- pick. autoref = Some ( m) ;
1071
- pick. unsize = if step. unsize {
1072
- Some ( step. self_ty )
1073
- } else {
1074
- None
1075
- } ;
1076
- }
1077
- picks
1056
+ r. map ( |mut pick| {
1057
+ pick. autoderefs = step. autoderefs ;
1058
+ pick. autoref = Some ( m) ;
1059
+ pick. unsize = if step. unsize {
1060
+ Some ( step. self_ty )
1061
+ } else {
1062
+ None
1063
+ } ;
1064
+ pick
1078
1065
} )
1079
1066
} )
1080
- } ) ;
1081
- match self . looking_for {
1082
- LookingFor :: MethodName ( _) => it. nth ( 0 ) ,
1083
- LookingFor :: ReturnType ( _) => {
1084
- let ret = it. filter_map ( |entry| entry. ok ( ) )
1085
- . flat_map ( |v| v)
1086
- . collect :: < Vec < _ > > ( ) ;
1087
-
1088
- if ret. len ( ) < 1 {
1089
- None
1090
- } else {
1091
- Some ( Ok ( ret) )
1092
- }
1093
- }
1094
- }
1067
+ } )
1068
+ . nth ( 0 )
1095
1069
}
1096
1070
1097
1071
fn pick_method ( & mut self , self_ty : Ty < ' tcx > ) -> Option < PickResult < ' tcx > > {
@@ -1130,7 +1104,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1130
1104
if applicable_candidates. len ( ) > 1 {
1131
1105
match self . collapse_candidates_to_trait_pick ( & applicable_candidates[ ..] ) {
1132
1106
Some ( pick) => {
1133
- return Some ( Ok ( vec ! [ pick] ) ) ;
1107
+ return Some ( Ok ( pick) ) ;
1134
1108
}
1135
1109
None => { }
1136
1110
}
@@ -1141,22 +1115,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1141
1115
return Some ( Err ( MethodError :: Ambiguity ( sources) ) ) ;
1142
1116
}
1143
1117
1144
- match self . looking_for {
1145
- LookingFor :: MethodName ( _) => applicable_candidates
1146
- . pop ( )
1147
- . map ( |probe| Ok ( vec ! [ probe. to_unadjusted_pick( ) ] ) ) ,
1148
- LookingFor :: ReturnType ( _) => {
1149
- let ret: Vec < _ > = applicable_candidates. iter ( )
1150
- . map ( |probe| probe. to_unadjusted_pick ( ) )
1151
- . collect ( ) ;
1152
-
1153
- if ret. len ( ) < 1 {
1154
- None
1155
- } else {
1156
- Some ( Ok ( ret) )
1157
- }
1158
- }
1159
- }
1118
+ applicable_candidates. pop ( ) . map ( |probe| Ok ( probe. to_unadjusted_pick ( ) ) )
1160
1119
}
1161
1120
1162
1121
fn consider_probe ( & self ,
0 commit comments