@@ -1067,20 +1067,23 @@ impl<'tcx> Predicate<'tcx> {
10671067
10681068 /// Returns the inner `PredicateAtom`.
10691069 ///
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
10721073 /// to end up at the wrong binding level.
10731074 pub fn skip_binders_unchecked ( self ) -> PredicateAtom < ' tcx > {
10741075 match self . kind ( ) {
10751076 & PredicateKind :: ForAll ( binder) => binder. skip_binder ( ) ,
1076- & ty :: PredicateKind :: Atom ( atom) => atom,
1077+ & PredicateKind :: Atom ( atom) => atom,
10771078 }
10781079 }
10791080
1081+ /// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
1082+ /// contained unbound variables by shifting these variables outwards.
10801083 pub fn bound_atom ( self , tcx : TyCtxt < ' tcx > ) -> Binder < PredicateAtom < ' tcx > > {
10811084 match self . kind ( ) {
10821085 & PredicateKind :: ForAll ( binder) => binder,
1083- & ty :: PredicateKind :: Atom ( atom) => Binder :: wrap_nonbinding ( tcx, atom) ,
1086+ & PredicateKind :: Atom ( atom) => Binder :: wrap_nonbinding ( tcx, atom) ,
10841087 }
10851088 }
10861089}
@@ -1105,7 +1108,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
11051108pub enum PredicateKind < ' tcx > {
11061109 /// `for<'a>: ...`
11071110 ForAll ( Binder < PredicateAtom < ' tcx > > ) ,
1108-
11091111 Atom ( PredicateAtom < ' tcx > ) ,
11101112}
11111113
@@ -1179,7 +1181,7 @@ pub struct CratePredicatesMap<'tcx> {
11791181 /// For each struct with outlive bounds, maps to a vector of the
11801182 /// predicate of its outlive bounds. If an item has no outlives
11811183 /// 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 ) ] > ,
11831185}
11841186
11851187impl < ' tcx > Predicate < ' tcx > {
@@ -1192,7 +1194,7 @@ impl<'tcx> Predicate<'tcx> {
11921194 self ,
11931195 tcx : TyCtxt < ' tcx > ,
11941196 trait_ref : & ty:: PolyTraitRef < ' tcx > ,
1195- ) -> ty :: Predicate < ' tcx > {
1197+ ) -> Predicate < ' tcx > {
11961198 // The interaction between HRTB and supertraits is not entirely
11971199 // obvious. Let me walk you (and myself) through an example.
11981200 //
@@ -1384,13 +1386,13 @@ impl ToPredicate<'tcx> for PredicateAtom<'tcx> {
13841386 #[ inline( always) ]
13851387 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
13861388 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 ) )
13881390 }
13891391}
13901392
13911393impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < TraitRef < ' tcx > > {
13921394 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 )
13941396 . to_predicate ( tcx)
13951397 }
13961398}
@@ -1407,51 +1409,29 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
14071409
14081410impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
14091411 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 )
14181414 }
14191415}
14201416
14211417impl < ' tcx > ToPredicate < ' tcx > for PolyRegionOutlivesPredicate < ' tcx > {
14221418 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 )
14311421 }
14321422}
14331423
14341424impl < ' tcx > ToPredicate < ' tcx > for PolyTypeOutlivesPredicate < ' tcx > {
14351425 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 )
14441428 }
14451429}
14461430
14471431impl < ' tcx > ToPredicate < ' tcx > for PolyProjectionPredicate < ' tcx > {
14481432 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 )
14551435 }
14561436}
14571437
@@ -1746,7 +1726,7 @@ pub struct ParamEnv<'tcx> {
17461726 // Specifically, the low bit represents Reveal, with 0 meaning `UserFacing`
17471727 // and 1 meaning `All`. The rest is the pointer.
17481728 //
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
17501730 // alignment. Lists start with a usize and are repr(C) so this should be
17511731 // fine; there is a debug_assert in the constructor as well.
17521732 //
@@ -1760,7 +1740,7 @@ pub struct ParamEnv<'tcx> {
17601740 ///
17611741 /// Note: This is packed into the `packed_data` usize above, use the
17621742 /// `caller_bounds()` method to access it.
1763- caller_bounds : PhantomData < & ' tcx List < ty :: Predicate < ' tcx > > > ,
1743+ caller_bounds : PhantomData < & ' tcx List < Predicate < ' tcx > > > ,
17641744
17651745 /// Typically, this is `Reveal::UserFacing`, but during codegen we
17661746 /// want `Reveal::All`.
@@ -1838,7 +1818,7 @@ impl<'tcx> ParamEnv<'tcx> {
18381818 }
18391819
18401820 #[ inline]
1841- pub fn caller_bounds ( self ) -> & ' tcx List < ty :: Predicate < ' tcx > > {
1821+ pub fn caller_bounds ( self ) -> & ' tcx List < Predicate < ' tcx > > {
18421822 // mask out bottom bit
18431823 unsafe { & * ( ( self . packed_data & ( !1 ) ) as * const _ ) }
18441824 }
@@ -1863,7 +1843,7 @@ impl<'tcx> ParamEnv<'tcx> {
18631843 /// Construct a trait environment with the given set of predicates.
18641844 #[ inline]
18651845 pub fn new (
1866- caller_bounds : & ' tcx List < ty :: Predicate < ' tcx > > ,
1846+ caller_bounds : & ' tcx List < Predicate < ' tcx > > ,
18671847 reveal : Reveal ,
18681848 def_id : Option < DefId > ,
18691849 ) -> Self {
0 commit comments