@@ -17,7 +17,8 @@ use rustc::ty::subst::Substs;
17
17
use rustc:: traits;
18
18
use rustc:: ty:: { self , ToPredicate , ToPolyTraitRef , TraitRef , TypeFoldable } ;
19
19
use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow } ;
20
- use rustc:: infer;
20
+ use rustc:: ty:: subst:: Subst ;
21
+ use rustc:: infer:: { self , InferOk } ;
21
22
22
23
use syntax:: ast;
23
24
use syntax_pos:: Span ;
@@ -159,7 +160,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
159
160
trait_def_id : DefId ,
160
161
self_ty : ty:: Ty < ' tcx > ,
161
162
opt_input_types : Option < Vec < ty:: Ty < ' tcx > > > )
162
- -> Option < ty:: MethodCallee < ' tcx > > {
163
+ -> Option < InferOk < ' tcx , ty:: MethodCallee < ' tcx > > > {
163
164
self . lookup_method_in_trait_adjusted ( span,
164
165
self_expr,
165
166
m_name,
@@ -190,7 +191,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
190
191
unsize : bool ,
191
192
self_ty : ty:: Ty < ' tcx > ,
192
193
opt_input_types : Option < Vec < ty:: Ty < ' tcx > > > )
193
- -> Option < ty:: MethodCallee < ' tcx > > {
194
+ -> Option < InferOk < ' tcx , ty:: MethodCallee < ' tcx > > > {
194
195
debug ! ( "lookup_in_trait_adjusted(self_ty={:?}, self_expr={:?}, \
195
196
m_name={}, trait_def_id={:?})",
196
197
self_ty,
@@ -236,6 +237,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
236
237
assert_eq ! ( generics. regions. len( ) , 0 ) ;
237
238
238
239
debug ! ( "lookup_in_trait_adjusted: method_item={:?}" , method_item) ;
240
+ let mut obligations = vec ! [ ] ;
239
241
240
242
// Instantiate late-bound regions and substitute the trait
241
243
// parameters into the method type to get the actual method type.
@@ -248,10 +250,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
248
250
let fn_sig = self . replace_late_bound_regions_with_fresh_var ( span,
249
251
infer:: FnCall ,
250
252
& fn_sig) . 0 ;
251
- let fn_sig = self . instantiate_type_scheme ( span, trait_ref. substs , & fn_sig) ;
253
+ let fn_sig = fn_sig. subst ( self . tcx , substs) ;
254
+ let fn_sig = match self . normalize_associated_types_in_as_infer_ok ( span, & fn_sig) {
255
+ InferOk { value, obligations : o } => {
256
+ obligations. extend ( o) ;
257
+ value
258
+ }
259
+ } ;
252
260
let transformed_self_ty = fn_sig. inputs ( ) [ 0 ] ;
253
- let method_ty = tcx. mk_fn_def ( def_id, trait_ref. substs ,
254
- ty:: Binder ( fn_sig) ) ;
261
+ let method_ty = tcx. mk_fn_def ( def_id, substs, ty:: Binder ( fn_sig) ) ;
255
262
256
263
debug ! ( "lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}" ,
257
264
method_ty,
@@ -265,18 +272,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
265
272
//
266
273
// Note that as the method comes from a trait, it should not have
267
274
// any late-bound regions appearing in its bounds.
268
- let method_bounds = self . instantiate_bounds ( span, def_id, trait_ref. substs ) ;
269
- assert ! ( !method_bounds. has_escaping_regions( ) ) ;
270
- self . add_obligations_for_parameters ( traits:: ObligationCause :: misc ( span, self . body_id ) ,
271
- & method_bounds) ;
275
+ let bounds = self . tcx . item_predicates ( def_id) . instantiate ( self . tcx , substs) ;
276
+ let bounds = match self . normalize_associated_types_in_as_infer_ok ( span, & bounds) {
277
+ InferOk { value, obligations : o } => {
278
+ obligations. extend ( o) ;
279
+ value
280
+ }
281
+ } ;
282
+ assert ! ( !bounds. has_escaping_regions( ) ) ;
272
283
273
- // Also register an obligation for the method type being well-formed.
274
- self . register_wf_obligation ( method_ty , span , traits:: MiscObligation ) ;
284
+ let cause = traits :: ObligationCause :: misc ( span , self . body_id ) ;
285
+ obligations . extend ( traits:: predicates_for_generics ( cause . clone ( ) , & bounds ) ) ;
275
286
276
- // FIXME(#18653) -- Try to resolve obligations, giving us more
277
- // typing information, which can sometimes be needed to avoid
278
- // pathological region inference failures.
279
- self . select_obligations_where_possible ( ) ;
287
+ // Also add an obligation for the method type being well-formed.
288
+ obligations. push ( traits:: Obligation :: new ( cause, ty:: Predicate :: WellFormed ( method_ty) ) ) ;
280
289
281
290
// Insert any adjustments needed (always an autoref of some mutability).
282
291
if let Some ( self_expr) = self_expr {
@@ -317,7 +326,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
317
326
318
327
debug ! ( "callee = {:?}" , callee) ;
319
328
320
- Some ( callee)
329
+ Some ( InferOk {
330
+ obligations,
331
+ value : callee
332
+ } )
321
333
}
322
334
323
335
pub fn resolve_ufcs ( & self ,
0 commit comments