@@ -442,7 +442,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
442
442
443
443
fn assemble_extension_candidates_for_trait ( & mut self ,
444
444
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={}) " ,
446
446
trait_def_id. repr( self . tcx( ) ) ) ;
447
447
448
448
// Check whether `trait_def_id` defines a method with suitable name:
@@ -471,8 +471,12 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
471
471
matching_index) ;
472
472
473
473
self . assemble_unboxed_closure_candidates ( trait_def_id,
474
- method,
474
+ method. clone ( ) ,
475
475
matching_index) ;
476
+
477
+ self . assemble_where_clause_candidates ( trait_def_id,
478
+ method,
479
+ matching_index) ;
476
480
}
477
481
478
482
fn assemble_extension_candidates_for_trait_impls ( & mut self ,
@@ -599,6 +603,35 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
599
603
}
600
604
}
601
605
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
+
602
635
///////////////////////////////////////////////////////////////////////////
603
636
// THE ACTUAL SEARCH
604
637
@@ -774,26 +807,26 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
774
807
match probe. kind {
775
808
InherentImplCandidate ( impl_def_id, ref substs) |
776
809
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
+
777
813
// Check whether the impl imposes obligations we have to worry about.
778
814
let impl_generics = ty:: lookup_item_type ( self . tcx ( ) , impl_def_id) . generics ;
779
815
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) ;
785
819
786
820
// Convert the bounds into obligations.
787
821
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) ;
792
825
debug ! ( "impl_obligations={}" , obligations. repr( self . tcx( ) ) ) ;
793
826
794
827
// 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) )
797
830
}
798
831
799
832
ObjectCandidate ( ..) |
0 commit comments