@@ -1149,17 +1149,16 @@ pub enum PredicateAtom<'tcx> {
11491149 TypeWellFormedFromEnv ( Ty < ' tcx > ) ,
11501150}
11511151
1152- impl < ' tcx > PredicateAtom < ' tcx > {
1152+ impl < ' tcx > Binder < PredicateAtom < ' tcx > > {
11531153 /// Wraps `self` with the given qualifier if this predicate has any unbound variables.
11541154 pub fn potentially_quantified (
11551155 self ,
11561156 tcx : TyCtxt < ' tcx > ,
11571157 qualifier : impl FnOnce ( Binder < PredicateAtom < ' tcx > > ) -> PredicateKind < ' tcx > ,
11581158 ) -> Predicate < ' tcx > {
1159- if self . has_escaping_bound_vars ( ) {
1160- qualifier ( Binder :: bind ( self ) )
1161- } else {
1162- PredicateKind :: Atom ( self )
1159+ match self . no_bound_vars ( ) {
1160+ Some ( atom) => PredicateKind :: Atom ( atom) ,
1161+ None => qualifier ( self ) ,
11631162 }
11641163 . to_predicate ( tcx)
11651164 }
@@ -1252,7 +1251,11 @@ impl<'tcx> Predicate<'tcx> {
12521251 let substs = trait_ref. skip_binder ( ) . substs ;
12531252 let pred = self . skip_binders ( ) ;
12541253 let new = pred. subst ( tcx, substs) ;
1255- if new != pred { new. potentially_quantified ( tcx, PredicateKind :: ForAll ) } else { self }
1254+ if new != pred {
1255+ ty:: Binder :: bind ( new) . potentially_quantified ( tcx, PredicateKind :: ForAll )
1256+ } else {
1257+ self
1258+ }
12561259 }
12571260}
12581261
@@ -1279,6 +1282,10 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
12791282 // Ok to skip binder since trait `DefId` does not care about regions.
12801283 self . skip_binder ( ) . def_id ( )
12811284 }
1285+
1286+ pub fn self_ty ( self ) -> ty:: Binder < Ty < ' tcx > > {
1287+ self . map_bound ( |trait_ref| trait_ref. self_ty ( ) )
1288+ }
12821289}
12831290
12841291#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , TyEncodable , TyDecodable ) ]
@@ -1403,37 +1410,39 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
14031410
14041411impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
14051412 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1406- PredicateAtom :: Trait ( self . value . skip_binder ( ) , self . constness )
1413+ self . value
1414+ . map_bound ( |value| PredicateAtom :: Trait ( value, self . constness ) )
14071415 . potentially_quantified ( tcx, PredicateKind :: ForAll )
14081416 }
14091417}
14101418
14111419impl < ' tcx > ToPredicate < ' tcx > for PolyRegionOutlivesPredicate < ' tcx > {
14121420 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1413- PredicateAtom :: RegionOutlives ( self . skip_binder ( ) )
1421+ self . map_bound ( |value| PredicateAtom :: RegionOutlives ( value ) )
14141422 . potentially_quantified ( tcx, PredicateKind :: ForAll )
14151423 }
14161424}
14171425
14181426impl < ' tcx > ToPredicate < ' tcx > for PolyTypeOutlivesPredicate < ' tcx > {
14191427 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1420- PredicateAtom :: TypeOutlives ( self . skip_binder ( ) )
1428+ self . map_bound ( |value| PredicateAtom :: TypeOutlives ( value ) )
14211429 . potentially_quantified ( tcx, PredicateKind :: ForAll )
14221430 }
14231431}
14241432
14251433impl < ' tcx > ToPredicate < ' tcx > for PolyProjectionPredicate < ' tcx > {
14261434 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1427- PredicateAtom :: Projection ( self . skip_binder ( ) )
1435+ self . map_bound ( |value| PredicateAtom :: Projection ( value ) )
14281436 . potentially_quantified ( tcx, PredicateKind :: ForAll )
14291437 }
14301438}
14311439
14321440impl < ' tcx > Predicate < ' tcx > {
14331441 pub fn to_opt_poly_trait_ref ( self ) -> Option < ConstnessAnd < PolyTraitRef < ' tcx > > > {
1434- match self . skip_binders ( ) {
1442+ let predicate = self . bound_atom ( ) ;
1443+ match predicate. skip_binder ( ) {
14351444 PredicateAtom :: Trait ( t, constness) => {
1436- Some ( ConstnessAnd { constness, value : ty :: Binder :: bind ( t. trait_ref ) } )
1445+ Some ( ConstnessAnd { constness, value : predicate . rebind ( t. trait_ref ) } )
14371446 }
14381447 PredicateAtom :: Projection ( ..)
14391448 | PredicateAtom :: Subtype ( ..)
@@ -1449,8 +1458,9 @@ impl<'tcx> Predicate<'tcx> {
14491458 }
14501459
14511460 pub fn to_opt_type_outlives ( self ) -> Option < PolyTypeOutlivesPredicate < ' tcx > > {
1452- match self . skip_binders ( ) {
1453- PredicateAtom :: TypeOutlives ( data) => Some ( ty:: Binder :: bind ( data) ) ,
1461+ let predicate = self . bound_atom ( ) ;
1462+ match predicate. skip_binder ( ) {
1463+ PredicateAtom :: TypeOutlives ( data) => Some ( predicate. rebind ( data) ) ,
14541464 PredicateAtom :: Trait ( ..)
14551465 | PredicateAtom :: Projection ( ..)
14561466 | PredicateAtom :: Subtype ( ..)
0 commit comments