@@ -21,8 +21,8 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMut
21
21
use rustc_middle:: ty:: fold:: TypeFoldable ;
22
22
use rustc_middle:: ty:: visit:: TypeVisitable ;
23
23
use rustc_middle:: ty:: {
24
- self , AdtKind , CanonicalUserType , DefIdTree , EarlyBinder , GenericParamDefKind , ToPolyTraitRef ,
25
- ToPredicate , Ty , UserType ,
24
+ self , AdtKind , CanonicalUserType , DefIdTree , EarlyBinder , GenericParamDefKind , ToPredicate , Ty ,
25
+ UserType ,
26
26
} ;
27
27
use rustc_middle:: ty:: { GenericArgKind , InternalSubsts , SubstsRef , UserSelfTy , UserSubsts } ;
28
28
use rustc_session:: lint;
@@ -650,12 +650,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
650
650
}
651
651
652
652
#[ instrument( skip( self ) , level = "debug" ) ]
653
- fn self_type_matches_expected_vid (
654
- & self ,
655
- trait_ref : ty:: PolyTraitRef < ' tcx > ,
656
- expected_vid : ty:: TyVid ,
657
- ) -> bool {
658
- let self_ty = self . shallow_resolve ( trait_ref. skip_binder ( ) . self_ty ( ) ) ;
653
+ fn self_type_matches_expected_vid ( & self , self_ty : Ty < ' tcx > , expected_vid : ty:: TyVid ) -> bool {
654
+ let self_ty = self . shallow_resolve ( self_ty) ;
659
655
debug ! ( ?self_ty) ;
660
656
661
657
match * self_ty. kind ( ) {
@@ -674,54 +670,61 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
674
670
pub ( in super :: super ) fn obligations_for_self_ty < ' b > (
675
671
& ' b self ,
676
672
self_ty : ty:: TyVid ,
677
- ) -> impl Iterator < Item = ( ty:: PolyTraitRef < ' tcx > , traits:: PredicateObligation < ' tcx > ) >
678
- + Captures < ' tcx >
679
- + ' b {
673
+ ) -> impl DoubleEndedIterator < Item = traits:: PredicateObligation < ' tcx > > + Captures < ' tcx > + ' b
674
+ {
680
675
// FIXME: consider using `sub_root_var` here so we
681
676
// can see through subtyping.
682
677
let ty_var_root = self . root_var ( self_ty) ;
683
678
trace ! ( "pending_obligations = {:#?}" , self . fulfillment_cx. borrow( ) . pending_obligations( ) ) ;
684
679
685
- self . fulfillment_cx
686
- . borrow ( )
687
- . pending_obligations ( )
688
- . into_iter ( )
689
- . filter_map ( move |obligation| {
690
- let bound_predicate = obligation. predicate . kind ( ) ;
691
- match bound_predicate. skip_binder ( ) {
692
- ty:: PredicateKind :: Projection ( data) => Some ( (
693
- bound_predicate. rebind ( data) . required_poly_trait_ref ( self . tcx ) ,
694
- obligation,
695
- ) ) ,
696
- ty:: PredicateKind :: Trait ( data) => {
697
- Some ( ( bound_predicate. rebind ( data) . to_poly_trait_ref ( ) , obligation) )
698
- }
699
- ty:: PredicateKind :: Subtype ( ..) => None ,
700
- ty:: PredicateKind :: Coerce ( ..) => None ,
701
- ty:: PredicateKind :: RegionOutlives ( ..) => None ,
702
- ty:: PredicateKind :: TypeOutlives ( ..) => None ,
703
- ty:: PredicateKind :: WellFormed ( ..) => None ,
704
- ty:: PredicateKind :: ObjectSafe ( ..) => None ,
705
- ty:: PredicateKind :: ConstEvaluatable ( ..) => None ,
706
- ty:: PredicateKind :: ConstEquate ( ..) => None ,
707
- // N.B., this predicate is created by breaking down a
708
- // `ClosureType: FnFoo()` predicate, where
709
- // `ClosureType` represents some `Closure`. It can't
710
- // possibly be referring to the current closure,
711
- // because we haven't produced the `Closure` for
712
- // this closure yet; this is exactly why the other
713
- // code is looking for a self type of an unresolved
714
- // inference variable.
715
- ty:: PredicateKind :: ClosureKind ( ..) => None ,
716
- ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => None ,
680
+ self . fulfillment_cx . borrow ( ) . pending_obligations ( ) . into_iter ( ) . filter_map (
681
+ move |obligation| match & obligation. predicate . kind ( ) . skip_binder ( ) {
682
+ ty:: PredicateKind :: Projection ( data)
683
+ if self . self_type_matches_expected_vid (
684
+ data. projection_ty . self_ty ( ) ,
685
+ ty_var_root,
686
+ ) =>
687
+ {
688
+ Some ( obligation)
717
689
}
718
- } )
719
- . filter ( move |( tr, _) | self . self_type_matches_expected_vid ( * tr, ty_var_root) )
690
+ ty:: PredicateKind :: Trait ( data)
691
+ if self . self_type_matches_expected_vid ( data. self_ty ( ) , ty_var_root) =>
692
+ {
693
+ Some ( obligation)
694
+ }
695
+
696
+ ty:: PredicateKind :: Trait ( ..)
697
+ | ty:: PredicateKind :: Projection ( ..)
698
+ | ty:: PredicateKind :: Subtype ( ..)
699
+ | ty:: PredicateKind :: Coerce ( ..)
700
+ | ty:: PredicateKind :: RegionOutlives ( ..)
701
+ | ty:: PredicateKind :: TypeOutlives ( ..)
702
+ | ty:: PredicateKind :: WellFormed ( ..)
703
+ | ty:: PredicateKind :: ObjectSafe ( ..)
704
+ | ty:: PredicateKind :: ConstEvaluatable ( ..)
705
+ | ty:: PredicateKind :: ConstEquate ( ..)
706
+ // N.B., this predicate is created by breaking down a
707
+ // `ClosureType: FnFoo()` predicate, where
708
+ // `ClosureType` represents some `Closure`. It can't
709
+ // possibly be referring to the current closure,
710
+ // because we haven't produced the `Closure` for
711
+ // this closure yet; this is exactly why the other
712
+ // code is looking for a self type of an unresolved
713
+ // inference variable.
714
+ | ty:: PredicateKind :: ClosureKind ( ..)
715
+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => None ,
716
+ } ,
717
+ )
720
718
}
721
719
722
720
pub ( in super :: super ) fn type_var_is_sized ( & self , self_ty : ty:: TyVid ) -> bool {
723
- self . obligations_for_self_ty ( self_ty)
724
- . any ( |( tr, _) | Some ( tr. def_id ( ) ) == self . tcx . lang_items ( ) . sized_trait ( ) )
721
+ let sized_did = self . tcx . lang_items ( ) . sized_trait ( ) ;
722
+ self . obligations_for_self_ty ( self_ty) . any ( |obligation| {
723
+ match obligation. predicate . kind ( ) . skip_binder ( ) {
724
+ ty:: PredicateKind :: Trait ( data) => Some ( data. def_id ( ) ) == sized_did,
725
+ _ => false ,
726
+ }
727
+ } )
725
728
}
726
729
727
730
pub ( in super :: super ) fn err_args ( & self , len : usize ) -> Vec < Ty < ' tcx > > {
0 commit comments