@@ -442,7 +442,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
442442
443443 fn assemble_extension_candidates_for_trait ( & mut self ,
444444 trait_def_id : ast:: DefId ) {
445- debug ! ( "assemble_extension_candidates_for_trait: trait_def_id={}" ,
445+ debug ! ( "assemble_extension_candidates_for_trait( trait_def_id={}) " ,
446446 trait_def_id. repr( self . tcx( ) ) ) ;
447447
448448 // Check whether `trait_def_id` defines a method with suitable name:
@@ -471,8 +471,12 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
471471 matching_index) ;
472472
473473 self . assemble_unboxed_closure_candidates ( trait_def_id,
474- method,
474+ method. clone ( ) ,
475475 matching_index) ;
476+
477+ self . assemble_where_clause_candidates ( trait_def_id,
478+ method,
479+ matching_index) ;
476480 }
477481
478482 fn assemble_extension_candidates_for_trait_impls ( & mut self ,
@@ -599,6 +603,35 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
599603 }
600604 }
601605
606+ fn assemble_where_clause_candidates ( & mut self ,
607+ trait_def_id : ast:: DefId ,
608+ method_ty : Rc < ty:: Method < ' tcx > > ,
609+ method_index : uint )
610+ {
611+ debug ! ( "assemble_where_clause_candidates(trait_def_id={})" ,
612+ trait_def_id. repr( self . tcx( ) ) ) ;
613+
614+ // Check whether there are any where-clauses pertaining to this trait.
615+ let caller_predicates =
616+ self . fcx . inh . param_env . caller_bounds . predicates . as_slice ( ) . to_vec ( ) ;
617+ for bound in traits:: elaborate_predicates ( self . tcx ( ) , caller_predicates)
618+ . filter_map ( |p| p. to_opt_poly_trait_ref ( ) )
619+ . filter ( |b| b. def_id ( ) == trait_def_id)
620+ {
621+ let xform_self_ty = self . xform_self_ty ( & method_ty, bound. substs ( ) ) ;
622+
623+ debug ! ( "assemble_where_clause_candidates: bound={} xform_self_ty={}" ,
624+ bound. repr( self . tcx( ) ) ,
625+ xform_self_ty. repr( self . tcx( ) ) ) ;
626+
627+ self . extension_candidates . push ( Candidate {
628+ xform_self_ty : xform_self_ty,
629+ method_ty : method_ty. clone ( ) ,
630+ kind : WhereClauseCandidate ( bound, method_index)
631+ } ) ;
632+ }
633+ }
634+
602635 ///////////////////////////////////////////////////////////////////////////
603636 // THE ACTUAL SEARCH
604637
@@ -774,26 +807,26 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
774807 match probe. kind {
775808 InherentImplCandidate ( impl_def_id, ref substs) |
776809 ExtensionImplCandidate ( impl_def_id, _, ref substs, _) => {
810+ let selcx = & mut traits:: SelectionContext :: new ( self . infcx ( ) , self . fcx ) ;
811+ let cause = traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ;
812+
777813 // Check whether the impl imposes obligations we have to worry about.
778814 let impl_generics = ty:: lookup_item_type ( self . tcx ( ) , impl_def_id) . generics ;
779815 let impl_bounds = impl_generics. to_bounds ( self . tcx ( ) , substs) ;
780- // FIXME(#20378) assoc type normalization here?
781-
782- // Erase any late-bound regions bound in the impl
783- // which appear in the bounds.
784- let impl_bounds = self . erase_late_bound_regions ( & ty:: Binder ( impl_bounds) ) ;
816+ let traits:: Normalized { value : impl_bounds,
817+ obligations : norm_obligations } =
818+ traits:: normalize ( selcx, cause. clone ( ) , & impl_bounds) ;
785819
786820 // Convert the bounds into obligations.
787821 let obligations =
788- traits:: predicates_for_generics (
789- self . tcx ( ) ,
790- traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ,
791- & impl_bounds) ;
822+ traits:: predicates_for_generics ( self . tcx ( ) ,
823+ cause. clone ( ) ,
824+ & impl_bounds) ;
792825 debug ! ( "impl_obligations={}" , obligations. repr( self . tcx( ) ) ) ;
793826
794827 // Evaluate those obligations to see if they might possibly hold.
795- let mut selcx = traits :: SelectionContext :: new ( self . infcx ( ) , self . fcx ) ;
796- obligations . all ( |o| selcx. evaluate_obligation ( o) )
828+ obligations . all ( |o| selcx. evaluate_obligation ( o ) ) &&
829+ norm_obligations . iter ( ) . all ( |o| selcx. evaluate_obligation ( o) )
797830 }
798831
799832 ObjectCandidate ( ..) |
0 commit comments