@@ -1116,21 +1116,17 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1116
1116
let steps = self . steps . clone ( ) ;
1117
1117
1118
1118
// find the first step that works
1119
- steps. iter ( ) . filter_map ( |step| self . pick_step ( step) ) . next ( )
1120
- }
1121
-
1122
- fn pick_step ( & mut self , step : & CandidateStep < ' tcx > ) -> Option < PickResult < ' tcx > > {
1123
- debug ! ( "pick_step: step={:?}" , step) ;
1124
-
1125
- if step. self_ty . references_error ( ) {
1126
- return None ;
1127
- }
1128
-
1129
- if let Some ( result) = self . pick_by_value_method ( step) {
1130
- return Some ( result) ;
1131
- }
1132
-
1133
- self . pick_autorefd_method ( step)
1119
+ steps
1120
+ . iter ( )
1121
+ . filter ( |step| {
1122
+ debug ! ( "pick_core: step={:?}" , step) ;
1123
+ !step. self_ty . references_error ( )
1124
+ } ) . flat_map ( |step| {
1125
+ self . pick_by_value_method ( step) . or_else ( || {
1126
+ self . pick_autorefd_method ( step, hir:: MutImmutable ) . or_else ( || {
1127
+ self . pick_autorefd_method ( step, hir:: MutMutable )
1128
+ } ) } ) } )
1129
+ . next ( )
1134
1130
}
1135
1131
1136
1132
fn pick_by_value_method ( & mut self , step : & CandidateStep < ' tcx > ) -> Option < PickResult < ' tcx > > {
@@ -1161,36 +1157,30 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
1161
1157
} )
1162
1158
}
1163
1159
1164
- fn pick_autorefd_method ( & mut self , step : & CandidateStep < ' tcx > ) -> Option < PickResult < ' tcx > > {
1160
+ fn pick_autorefd_method ( & mut self , step : & CandidateStep < ' tcx > , mutbl : hir:: Mutability )
1161
+ -> Option < PickResult < ' tcx > > {
1165
1162
let tcx = self . tcx ;
1166
1163
1167
1164
// In general, during probing we erase regions. See
1168
1165
// `impl_self_ty()` for an explanation.
1169
1166
let region = tcx. types . re_erased ;
1170
1167
1171
- // Search through mutabilities in order to find one where pick works:
1172
- [ hir:: MutImmutable , hir:: MutMutable ]
1173
- . iter ( )
1174
- . filter_map ( |& m| {
1175
- let autoref_ty = tcx. mk_ref ( region,
1176
- ty:: TypeAndMut {
1177
- ty : step. self_ty ,
1178
- mutbl : m,
1179
- } ) ;
1180
- self . pick_method ( autoref_ty) . map ( |r| {
1181
- r. map ( |mut pick| {
1182
- pick. autoderefs = step. autoderefs ;
1183
- pick. autoref = Some ( m) ;
1184
- pick. unsize = if step. unsize {
1185
- Some ( step. self_ty )
1186
- } else {
1187
- None
1188
- } ;
1189
- pick
1190
- } )
1191
- } )
1168
+ let autoref_ty = tcx. mk_ref ( region,
1169
+ ty:: TypeAndMut {
1170
+ ty : step. self_ty , mutbl
1171
+ } ) ;
1172
+ self . pick_method ( autoref_ty) . map ( |r| {
1173
+ r. map ( |mut pick| {
1174
+ pick. autoderefs = step. autoderefs ;
1175
+ pick. autoref = Some ( mutbl) ;
1176
+ pick. unsize = if step. unsize {
1177
+ Some ( step. self_ty )
1178
+ } else {
1179
+ None
1180
+ } ;
1181
+ pick
1192
1182
} )
1193
- . nth ( 0 )
1183
+ } )
1194
1184
}
1195
1185
1196
1186
fn pick_method ( & mut self , self_ty : Ty < ' tcx > ) -> Option < PickResult < ' tcx > > {
0 commit comments