@@ -17,7 +17,8 @@ use rustc::ty::subst::Substs;
1717use rustc:: traits;
1818use rustc:: ty:: { self , ToPredicate , ToPolyTraitRef , TraitRef , TypeFoldable } ;
1919use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow } ;
20- use rustc:: infer;
20+ use rustc:: ty:: subst:: Subst ;
21+ use rustc:: infer:: { self , InferOk } ;
2122
2223use syntax:: ast;
2324use syntax_pos:: Span ;
@@ -159,7 +160,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
159160 trait_def_id : DefId ,
160161 self_ty : ty:: Ty < ' tcx > ,
161162 opt_input_types : Option < Vec < ty:: Ty < ' tcx > > > )
162- -> Option < ty:: MethodCallee < ' tcx > > {
163+ -> Option < InferOk < ' tcx , ty:: MethodCallee < ' tcx > > > {
163164 self . lookup_method_in_trait_adjusted ( span,
164165 self_expr,
165166 m_name,
@@ -190,7 +191,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
190191 unsize : bool ,
191192 self_ty : ty:: Ty < ' tcx > ,
192193 opt_input_types : Option < Vec < ty:: Ty < ' tcx > > > )
193- -> Option < ty:: MethodCallee < ' tcx > > {
194+ -> Option < InferOk < ' tcx , ty:: MethodCallee < ' tcx > > > {
194195 debug ! ( "lookup_in_trait_adjusted(self_ty={:?}, self_expr={:?}, \
195196 m_name={}, trait_def_id={:?})",
196197 self_ty,
@@ -236,6 +237,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
236237 assert_eq ! ( generics. regions. len( ) , 0 ) ;
237238
238239 debug ! ( "lookup_in_trait_adjusted: method_item={:?}" , method_item) ;
240+ let mut obligations = vec ! [ ] ;
239241
240242 // Instantiate late-bound regions and substitute the trait
241243 // parameters into the method type to get the actual method type.
@@ -248,10 +250,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
248250 let fn_sig = self . replace_late_bound_regions_with_fresh_var ( span,
249251 infer:: FnCall ,
250252 & 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+ } ;
252260 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) ) ;
255262
256263 debug ! ( "lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}" ,
257264 method_ty,
@@ -265,18 +272,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
265272 //
266273 // Note that as the method comes from a trait, it should not have
267274 // 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( ) ) ;
272283
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 ) ) ;
275286
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) ) ) ;
280289
281290 // Insert any adjustments needed (always an autoref of some mutability).
282291 if let Some ( self_expr) = self_expr {
@@ -317,7 +326,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
317326
318327 debug ! ( "callee = {:?}" , callee) ;
319328
320- Some ( callee)
329+ Some ( InferOk {
330+ obligations,
331+ value : callee
332+ } )
321333 }
322334
323335 pub fn resolve_ufcs ( & self ,
0 commit comments