@@ -1067,20 +1067,23 @@ impl<'tcx> Predicate<'tcx> {
1067
1067
1068
1068
/// Returns the inner `PredicateAtom`.
1069
1069
///
1070
- /// Note that this method does not check if predicate has unbound variables,
1071
- /// rebinding the returned atom potentially causes the previously bound variables
1070
+ /// Note that this method does not check if the predicate has unbound variables.
1071
+ ///
1072
+ /// Rebinding the returned atom can causes the previously bound variables
1072
1073
/// to end up at the wrong binding level.
1073
1074
pub fn skip_binders_unchecked ( self ) -> PredicateAtom < ' tcx > {
1074
1075
match self . kind ( ) {
1075
1076
& PredicateKind :: ForAll ( binder) => binder. skip_binder ( ) ,
1076
- & ty :: PredicateKind :: Atom ( atom) => atom,
1077
+ & PredicateKind :: Atom ( atom) => atom,
1077
1078
}
1078
1079
}
1079
1080
1081
+ /// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
1082
+ /// contained unbound variables by shifting these variables outwards.
1080
1083
pub fn bound_atom ( self , tcx : TyCtxt < ' tcx > ) -> Binder < PredicateAtom < ' tcx > > {
1081
1084
match self . kind ( ) {
1082
1085
& PredicateKind :: ForAll ( binder) => binder,
1083
- & ty :: PredicateKind :: Atom ( atom) => Binder :: wrap_nonbinding ( tcx, atom) ,
1086
+ & PredicateKind :: Atom ( atom) => Binder :: wrap_nonbinding ( tcx, atom) ,
1084
1087
}
1085
1088
}
1086
1089
}
@@ -1105,7 +1108,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
1105
1108
pub enum PredicateKind < ' tcx > {
1106
1109
/// `for<'a>: ...`
1107
1110
ForAll ( Binder < PredicateAtom < ' tcx > > ) ,
1108
-
1109
1111
Atom ( PredicateAtom < ' tcx > ) ,
1110
1112
}
1111
1113
@@ -1179,7 +1181,7 @@ pub struct CratePredicatesMap<'tcx> {
1179
1181
/// For each struct with outlive bounds, maps to a vector of the
1180
1182
/// predicate of its outlive bounds. If an item has no outlives
1181
1183
/// bounds, it will have no entry.
1182
- pub predicates : FxHashMap < DefId , & ' tcx [ ( ty :: Predicate < ' tcx > , Span ) ] > ,
1184
+ pub predicates : FxHashMap < DefId , & ' tcx [ ( Predicate < ' tcx > , Span ) ] > ,
1183
1185
}
1184
1186
1185
1187
impl < ' tcx > Predicate < ' tcx > {
@@ -1192,7 +1194,7 @@ impl<'tcx> Predicate<'tcx> {
1192
1194
self ,
1193
1195
tcx : TyCtxt < ' tcx > ,
1194
1196
trait_ref : & ty:: PolyTraitRef < ' tcx > ,
1195
- ) -> ty :: Predicate < ' tcx > {
1197
+ ) -> Predicate < ' tcx > {
1196
1198
// The interaction between HRTB and supertraits is not entirely
1197
1199
// obvious. Let me walk you (and myself) through an example.
1198
1200
//
@@ -1384,13 +1386,13 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
1384
1386
#[ inline( always) ]
1385
1387
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1386
1388
debug_assert ! ( !self . has_escaping_bound_vars( ) , "escaping bound vars for {:?}" , self ) ;
1387
- tcx. mk_predicate ( ty :: PredicateKind :: Atom ( self ) )
1389
+ tcx. mk_predicate ( PredicateKind :: Atom ( self ) )
1388
1390
}
1389
1391
}
1390
1392
1391
1393
impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < TraitRef < ' tcx > > {
1392
1394
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1393
- ty :: PredicateAtom :: Trait ( ty:: TraitPredicate { trait_ref : self . value } , self . constness )
1395
+ PredicateAtom :: Trait ( ty:: TraitPredicate { trait_ref : self . value } , self . constness )
1394
1396
. to_predicate ( tcx)
1395
1397
}
1396
1398
}
@@ -1407,51 +1409,29 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
1407
1409
1408
1410
impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
1409
1411
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1410
- if let Some ( pred) = self . value . no_bound_vars ( ) {
1411
- ty:: PredicateAtom :: Trait ( pred, self . constness ) . to_predicate ( tcx)
1412
- } else {
1413
- ty:: PredicateKind :: ForAll (
1414
- self . value . map_bound ( |pred| ty:: PredicateAtom :: Trait ( pred, self . constness ) ) ,
1415
- )
1416
- . to_predicate ( tcx)
1417
- }
1412
+ PredicateAtom :: Trait ( self . value . skip_binder ( ) , self . constness )
1413
+ . potentially_quantified ( tcx, PredicateKind :: ForAll )
1418
1414
}
1419
1415
}
1420
1416
1421
1417
impl < ' tcx > ToPredicate < ' tcx > for PolyRegionOutlivesPredicate < ' tcx > {
1422
1418
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1423
- if let Some ( outlives) = self . no_bound_vars ( ) {
1424
- PredicateAtom :: RegionOutlives ( outlives) . to_predicate ( tcx)
1425
- } else {
1426
- ty:: PredicateKind :: ForAll (
1427
- self . map_bound ( |outlives| PredicateAtom :: RegionOutlives ( outlives) ) ,
1428
- )
1429
- . to_predicate ( tcx)
1430
- }
1419
+ PredicateAtom :: RegionOutlives ( self . skip_binder ( ) )
1420
+ . potentially_quantified ( tcx, PredicateKind :: ForAll )
1431
1421
}
1432
1422
}
1433
1423
1434
1424
impl < ' tcx > ToPredicate < ' tcx > for PolyTypeOutlivesPredicate < ' tcx > {
1435
1425
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1436
- if let Some ( outlives) = self . no_bound_vars ( ) {
1437
- PredicateAtom :: TypeOutlives ( outlives) . to_predicate ( tcx)
1438
- } else {
1439
- ty:: PredicateKind :: ForAll (
1440
- self . map_bound ( |outlives| PredicateAtom :: TypeOutlives ( outlives) ) ,
1441
- )
1442
- . to_predicate ( tcx)
1443
- }
1426
+ PredicateAtom :: TypeOutlives ( self . skip_binder ( ) )
1427
+ . potentially_quantified ( tcx, PredicateKind :: ForAll )
1444
1428
}
1445
1429
}
1446
1430
1447
1431
impl < ' tcx > ToPredicate < ' tcx > for PolyProjectionPredicate < ' tcx > {
1448
1432
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1449
- if let Some ( proj) = self . no_bound_vars ( ) {
1450
- PredicateAtom :: Projection ( proj) . to_predicate ( tcx)
1451
- } else {
1452
- ty:: PredicateKind :: ForAll ( self . map_bound ( |proj| PredicateAtom :: Projection ( proj) ) )
1453
- . to_predicate ( tcx)
1454
- }
1433
+ PredicateAtom :: Projection ( self . skip_binder ( ) )
1434
+ . potentially_quantified ( tcx, PredicateKind :: ForAll )
1455
1435
}
1456
1436
}
1457
1437
@@ -1746,7 +1726,7 @@ pub struct ParamEnv<'tcx> {
1746
1726
// Specifically, the low bit represents Reveal, with 0 meaning `UserFacing`
1747
1727
// and 1 meaning `All`. The rest is the pointer.
1748
1728
//
1749
- // This relies on the List<ty:: Predicate<'tcx>> type having at least 2-byte
1729
+ // This relies on the List<Predicate<'tcx>> type having at least 2-byte
1750
1730
// alignment. Lists start with a usize and are repr(C) so this should be
1751
1731
// fine; there is a debug_assert in the constructor as well.
1752
1732
//
@@ -1760,7 +1740,7 @@ pub struct ParamEnv<'tcx> {
1760
1740
///
1761
1741
/// Note: This is packed into the `packed_data` usize above, use the
1762
1742
/// `caller_bounds()` method to access it.
1763
- caller_bounds : PhantomData < & ' tcx List < ty :: Predicate < ' tcx > > > ,
1743
+ caller_bounds : PhantomData < & ' tcx List < Predicate < ' tcx > > > ,
1764
1744
1765
1745
/// Typically, this is `Reveal::UserFacing`, but during codegen we
1766
1746
/// want `Reveal::All`.
@@ -1838,7 +1818,7 @@ impl<'tcx> ParamEnv<'tcx> {
1838
1818
}
1839
1819
1840
1820
#[ inline]
1841
- pub fn caller_bounds ( self ) -> & ' tcx List < ty :: Predicate < ' tcx > > {
1821
+ pub fn caller_bounds ( self ) -> & ' tcx List < Predicate < ' tcx > > {
1842
1822
// mask out bottom bit
1843
1823
unsafe { & * ( ( self . packed_data & ( !1 ) ) as * const _ ) }
1844
1824
}
@@ -1863,7 +1843,7 @@ impl<'tcx> ParamEnv<'tcx> {
1863
1843
/// Construct a trait environment with the given set of predicates.
1864
1844
#[ inline]
1865
1845
pub fn new (
1866
- caller_bounds : & ' tcx List < ty :: Predicate < ' tcx > > ,
1846
+ caller_bounds : & ' tcx List < Predicate < ' tcx > > ,
1867
1847
reveal : Reveal ,
1868
1848
def_id : Option < DefId > ,
1869
1849
) -> Self {
0 commit comments