@@ -173,34 +173,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
173
173
expected_ty : Ty < ' tcx > ,
174
174
) -> ( Option < ExpectedSig < ' tcx > > , Option < ty:: ClosureKind > ) {
175
175
match * expected_ty. kind ( ) {
176
- ty:: Opaque ( def_id, substs) => {
177
- let bounds = self . tcx . bound_explicit_item_bounds ( def_id) ;
178
- let sig =
179
- bounds. subst_iter_copied ( self . tcx , substs) . find_map ( |( pred, span) | match pred
180
- . kind ( )
181
- . skip_binder ( )
182
- {
183
- ty:: PredicateKind :: Projection ( proj_predicate) => self
184
- . deduce_sig_from_projection (
185
- Some ( span) ,
186
- pred. kind ( ) . rebind ( proj_predicate) ,
187
- ) ,
188
- _ => None ,
189
- } ) ;
190
-
191
- let kind = bounds
192
- . 0
193
- . iter ( )
194
- . filter_map ( |( pred, _) | match pred. kind ( ) . skip_binder ( ) {
195
- ty:: PredicateKind :: Trait ( tp) => {
196
- self . tcx . fn_trait_kind_from_lang_item ( tp. def_id ( ) )
197
- }
198
- _ => None ,
199
- } )
200
- . fold ( None , |best, cur| Some ( best. map_or ( cur, |best| cmp:: min ( best, cur) ) ) ) ;
201
- trace ! ( ?sig, ?kind) ;
202
- ( sig, kind)
203
- }
176
+ ty:: Opaque ( def_id, substs) => self . deduce_signature_from_predicates (
177
+ self . tcx . bound_explicit_item_bounds ( def_id) . subst_iter_copied ( self . tcx , substs) ,
178
+ ) ,
204
179
ty:: Dynamic ( ref object_type, ..) => {
205
180
let sig = object_type. projection_bounds ( ) . find_map ( |pb| {
206
181
let pb = pb. with_self_ty ( self . tcx , self . tcx . types . trait_object_dummy_self ) ;
@@ -211,7 +186,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
211
186
. and_then ( |did| self . tcx . fn_trait_kind_from_lang_item ( did) ) ;
212
187
( sig, kind)
213
188
}
214
- ty:: Infer ( ty:: TyVar ( vid) ) => self . deduce_expectations_from_obligations ( vid) ,
189
+ ty:: Infer ( ty:: TyVar ( vid) ) => self . deduce_signature_from_predicates (
190
+ self . obligations_for_self_ty ( vid) . map ( |obl| ( obl. predicate , obl. cause . span ) ) ,
191
+ ) ,
215
192
ty:: FnPtr ( sig) => {
216
193
let expected_sig = ExpectedSig { cause_span : None , sig } ;
217
194
( Some ( expected_sig) , Some ( ty:: ClosureKind :: Fn ) )
@@ -220,19 +197,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220
197
}
221
198
}
222
199
223
- fn deduce_expectations_from_obligations (
200
+ fn deduce_signature_from_predicates (
224
201
& self ,
225
- expected_vid : ty:: TyVid ,
202
+ predicates : impl DoubleEndedIterator < Item = ( ty:: Predicate < ' tcx > , Span ) > ,
226
203
) -> ( Option < ExpectedSig < ' tcx > > , Option < ty:: ClosureKind > ) {
227
204
let mut expected_sig = None ;
228
205
let mut expected_kind = None ;
229
206
230
- for obligation in traits:: elaborate_obligations (
207
+ for obligation in traits:: elaborate_predicates_with_span (
231
208
self . tcx ,
232
209
// Reverse the obligations here, since `elaborate_*` uses a stack,
233
210
// and we want to keep inference generally in the same order of
234
211
// the registered obligations.
235
- self . obligations_for_self_ty ( expected_vid ) . rev ( ) . collect ( ) ,
212
+ predicates . rev ( ) ,
236
213
) {
237
214
debug ! ( ?obligation. predicate) ;
238
215
let bound_predicate = obligation. predicate . kind ( ) ;
0 commit comments