@@ -21,8 +21,8 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMut
2121use rustc_middle:: ty:: fold:: TypeFoldable ;
2222use rustc_middle:: ty:: visit:: TypeVisitable ;
2323use 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 ,
2626} ;
2727use rustc_middle:: ty:: { GenericArgKind , InternalSubsts , SubstsRef , UserSelfTy , UserSubsts } ;
2828use rustc_session:: lint;
@@ -650,12 +650,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
650650 }
651651
652652 #[ 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) ;
659655 debug ! ( ?self_ty) ;
660656
661657 match * self_ty. kind ( ) {
@@ -674,54 +670,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
674670 pub ( in super :: super ) fn obligations_for_self_ty < ' b > (
675671 & ' b self ,
676672 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 {
680674 // FIXME: consider using `sub_root_var` here so we
681675 // can see through subtyping.
682676 let ty_var_root = self . root_var ( self_ty) ;
683677 trace ! ( "pending_obligations = {:#?}" , self . fulfillment_cx. borrow( ) . pending_obligations( ) ) ;
684678
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)
717688 }
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+ )
720717 }
721718
722719 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+ } )
725727 }
726728
727729 pub ( in super :: super ) fn err_args ( & self , len : usize ) -> Vec < Ty < ' tcx > > {
0 commit comments