@@ -1149,17 +1149,16 @@ pub enum PredicateAtom<'tcx> {
1149
1149
TypeWellFormedFromEnv ( Ty < ' tcx > ) ,
1150
1150
}
1151
1151
1152
- impl < ' tcx > PredicateAtom < ' tcx > {
1152
+ impl < ' tcx > Binder < PredicateAtom < ' tcx > > {
1153
1153
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
1154
1154
pub fn potentially_quantified (
1155
1155
self ,
1156
1156
tcx : TyCtxt < ' tcx > ,
1157
1157
qualifier : impl FnOnce ( Binder < PredicateAtom < ' tcx > > ) -> PredicateKind < ' tcx > ,
1158
1158
) -> 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 ) ,
1163
1162
}
1164
1163
. to_predicate ( tcx)
1165
1164
}
@@ -1252,7 +1251,11 @@ impl<'tcx> Predicate<'tcx> {
1252
1251
let substs = trait_ref. skip_binder ( ) . substs ;
1253
1252
let pred = self . skip_binders ( ) ;
1254
1253
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
+ }
1256
1259
}
1257
1260
}
1258
1261
@@ -1279,6 +1282,10 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
1279
1282
// Ok to skip binder since trait `DefId` does not care about regions.
1280
1283
self . skip_binder ( ) . def_id ( )
1281
1284
}
1285
+
1286
+ pub fn self_ty ( self ) -> ty:: Binder < Ty < ' tcx > > {
1287
+ self . map_bound ( |trait_ref| trait_ref. self_ty ( ) )
1288
+ }
1282
1289
}
1283
1290
1284
1291
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Debug , TyEncodable , TyDecodable ) ]
@@ -1403,37 +1410,39 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
1403
1410
1404
1411
impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
1405
1412
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 ) )
1407
1415
. potentially_quantified ( tcx, PredicateKind :: ForAll )
1408
1416
}
1409
1417
}
1410
1418
1411
1419
impl < ' tcx > ToPredicate < ' tcx > for PolyRegionOutlivesPredicate < ' tcx > {
1412
1420
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1413
- PredicateAtom :: RegionOutlives ( self . skip_binder ( ) )
1421
+ self . map_bound ( |value| PredicateAtom :: RegionOutlives ( value ) )
1414
1422
. potentially_quantified ( tcx, PredicateKind :: ForAll )
1415
1423
}
1416
1424
}
1417
1425
1418
1426
impl < ' tcx > ToPredicate < ' tcx > for PolyTypeOutlivesPredicate < ' tcx > {
1419
1427
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1420
- PredicateAtom :: TypeOutlives ( self . skip_binder ( ) )
1428
+ self . map_bound ( |value| PredicateAtom :: TypeOutlives ( value ) )
1421
1429
. potentially_quantified ( tcx, PredicateKind :: ForAll )
1422
1430
}
1423
1431
}
1424
1432
1425
1433
impl < ' tcx > ToPredicate < ' tcx > for PolyProjectionPredicate < ' tcx > {
1426
1434
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1427
- PredicateAtom :: Projection ( self . skip_binder ( ) )
1435
+ self . map_bound ( |value| PredicateAtom :: Projection ( value ) )
1428
1436
. potentially_quantified ( tcx, PredicateKind :: ForAll )
1429
1437
}
1430
1438
}
1431
1439
1432
1440
impl < ' tcx > Predicate < ' tcx > {
1433
1441
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 ( ) {
1435
1444
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 ) } )
1437
1446
}
1438
1447
PredicateAtom :: Projection ( ..)
1439
1448
| PredicateAtom :: Subtype ( ..)
@@ -1449,8 +1458,9 @@ impl<'tcx> Predicate<'tcx> {
1449
1458
}
1450
1459
1451
1460
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) ) ,
1454
1464
PredicateAtom :: Trait ( ..)
1455
1465
| PredicateAtom :: Projection ( ..)
1456
1466
| PredicateAtom :: Subtype ( ..)
0 commit comments