@@ -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,60 @@ 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 Iterator < Item = traits:: PredicateObligation < ' tcx > > + Captures < ' tcx > + ' b {
680
674
// FIXME: consider using `sub_root_var` here so we
681
675
// can see through subtyping.
682
676
let ty_var_root = self . root_var ( self_ty) ;
683
677
trace ! ( "pending_obligations = {:#?}" , self . fulfillment_cx. borrow( ) . pending_obligations( ) ) ;
684
678
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 ,
679
+ self . fulfillment_cx . borrow ( ) . pending_obligations ( ) . into_iter ( ) . filter_map (
680
+ move |obligation| match & obligation. predicate . kind ( ) . skip_binder ( ) {
681
+ ty:: PredicateKind :: Projection ( data)
682
+ if self . self_type_matches_expected_vid (
683
+ data. projection_ty . self_ty ( ) ,
684
+ ty_var_root,
685
+ ) =>
686
+ {
687
+ Some ( obligation)
717
688
}
718
- } )
719
- . filter ( move |( tr, _) | self . self_type_matches_expected_vid ( * tr, ty_var_root) )
689
+ ty:: PredicateKind :: Trait ( data)
690
+ if self . self_type_matches_expected_vid ( data. self_ty ( ) , ty_var_root) =>
691
+ {
692
+ Some ( obligation)
693
+ }
694
+
695
+ ty:: PredicateKind :: Trait ( ..)
696
+ | ty:: PredicateKind :: Projection ( ..)
697
+ | ty:: PredicateKind :: Subtype ( ..)
698
+ | ty:: PredicateKind :: Coerce ( ..)
699
+ | ty:: PredicateKind :: RegionOutlives ( ..)
700
+ | ty:: PredicateKind :: TypeOutlives ( ..)
701
+ | ty:: PredicateKind :: WellFormed ( ..)
702
+ | ty:: PredicateKind :: ObjectSafe ( ..)
703
+ | ty:: PredicateKind :: ConstEvaluatable ( ..)
704
+ | ty:: PredicateKind :: ConstEquate ( ..)
705
+ // N.B., this predicate is created by breaking down a
706
+ // `ClosureType: FnFoo()` predicate, where
707
+ // `ClosureType` represents some `Closure`. It can't
708
+ // possibly be referring to the current closure,
709
+ // because we haven't produced the `Closure` for
710
+ // this closure yet; this is exactly why the other
711
+ // code is looking for a self type of an unresolved
712
+ // inference variable.
713
+ | ty:: PredicateKind :: ClosureKind ( ..)
714
+ | ty:: PredicateKind :: TypeWellFormedFromEnv ( ..) => None ,
715
+ } ,
716
+ )
720
717
}
721
718
722
719
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 ( ) )
720
+ let sized_did = self . tcx . lang_items ( ) . sized_trait ( ) ;
721
+ self . obligations_for_self_ty ( self_ty) . any ( |obligation| {
722
+ match obligation. predicate . kind ( ) . skip_binder ( ) {
723
+ ty:: PredicateKind :: Trait ( data) => Some ( data. def_id ( ) ) == sized_did,
724
+ _ => false ,
725
+ }
726
+ } )
725
727
}
726
728
727
729
pub ( in super :: super ) fn err_args ( & self , len : usize ) -> Vec < Ty < ' tcx > > {
0 commit comments