@@ -1053,8 +1053,9 @@ impl<'tcx> Predicate<'tcx> {
10531053 ///
10541054 /// Note that this method panics in case this predicate has unbound variables.
10551055 pub fn skip_binders ( self ) -> PredicateAtom < ' tcx > {
1056+ // TODO no_escaping_vars
10561057 match self . kind ( ) {
1057- & PredicateKind :: ForAll ( binder) => binder. skip_binder ( ) . skip_binders ( ) ,
1058+ & PredicateKind :: ForAll ( binder) => binder. skip_binder ( ) ,
10581059 & ty:: PredicateKind :: Atom ( atom) => atom,
10591060 }
10601061 }
@@ -1066,33 +1067,17 @@ impl<'tcx> Predicate<'tcx> {
10661067 /// to end up at the wrong binding level.
10671068 pub fn skip_binders_unchecked ( self ) -> PredicateAtom < ' tcx > {
10681069 match self . kind ( ) {
1069- & PredicateKind :: ForAll ( binder) => binder. skip_binder ( ) . skip_binders ( ) ,
1070+ & PredicateKind :: ForAll ( binder) => binder. skip_binder ( ) ,
10701071 & ty:: PredicateKind :: Atom ( atom) => atom,
10711072 }
10721073 }
10731074
10741075 pub fn bound_atom ( self , tcx : TyCtxt < ' tcx > ) -> Binder < PredicateAtom < ' tcx > > {
10751076 match self . kind ( ) {
1076- & PredicateKind :: ForAll ( binder) => binder. map_bound ( |inner| match inner. kind ( ) {
1077- ty:: PredicateKind :: ForAll ( _) => bug ! ( "unexpect forall" ) ,
1078- & ty:: PredicateKind :: Atom ( atom) => atom,
1079- } ) ,
1077+ & PredicateKind :: ForAll ( binder) => binder,
10801078 & ty:: PredicateKind :: Atom ( atom) => Binder :: wrap_nonbinding ( tcx, atom) ,
10811079 }
10821080 }
1083-
1084- /// Wraps `self` with the given qualifier if this predicate has any unbound variables.
1085- pub fn potentially_quantified (
1086- self ,
1087- tcx : TyCtxt < ' tcx > ,
1088- qualifier : impl FnOnce ( Binder < Predicate < ' tcx > > ) -> PredicateKind < ' tcx > ,
1089- ) -> Predicate < ' tcx > {
1090- if self . has_escaping_bound_vars ( ) {
1091- qualifier ( Binder :: bind ( self ) ) . to_predicate ( tcx)
1092- } else {
1093- self
1094- }
1095- }
10961081}
10971082
10981083impl < ' a , ' tcx > HashStable < StableHashingContext < ' a > > for Predicate < ' tcx > {
@@ -1114,7 +1099,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
11141099#[ derive( HashStable , TypeFoldable ) ]
11151100pub enum PredicateKind < ' tcx > {
11161101 /// `for<'a>: ...`
1117- ForAll ( Binder < Predicate < ' tcx > > ) ,
1102+ ForAll ( Binder < PredicateAtom < ' tcx > > ) ,
11181103
11191104 Atom ( PredicateAtom < ' tcx > ) ,
11201105}
@@ -1162,6 +1147,22 @@ pub enum PredicateAtom<'tcx> {
11621147 ConstEquate ( & ' tcx Const < ' tcx > , & ' tcx Const < ' tcx > ) ,
11631148}
11641149
1150+ impl < ' tcx > PredicateAtom < ' tcx > {
1151+ /// Wraps `self` with the given qualifier if this predicate has any unbound variables.
1152+ pub fn potentially_quantified (
1153+ self ,
1154+ tcx : TyCtxt < ' tcx > ,
1155+ qualifier : impl FnOnce ( Binder < PredicateAtom < ' tcx > > ) -> PredicateKind < ' tcx > ,
1156+ ) -> Predicate < ' tcx > {
1157+ if self . has_escaping_bound_vars ( ) {
1158+ qualifier ( Binder :: bind ( self ) )
1159+ } else {
1160+ PredicateKind :: Atom ( self )
1161+ }
1162+ . to_predicate ( tcx)
1163+ }
1164+ }
1165+
11651166/// The crate outlives map is computed during typeck and contains the
11661167/// outlives of every item in the local crate. You should not use it
11671168/// directly, because to do so will make your pass dependent on the
@@ -1249,11 +1250,7 @@ impl<'tcx> Predicate<'tcx> {
12491250 let substs = trait_ref. skip_binder ( ) . substs ;
12501251 let pred = self . skip_binders ( ) ;
12511252 let new = pred. subst ( tcx, substs) ;
1252- if new != pred {
1253- new. to_predicate ( tcx) . potentially_quantified ( tcx, PredicateKind :: ForAll )
1254- } else {
1255- self
1256- }
1253+ if new != pred { new. potentially_quantified ( tcx, PredicateKind :: ForAll ) } else { self }
12571254 }
12581255}
12591256
@@ -1381,6 +1378,7 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
13811378impl ToPredicate < ' tcx > for PredicateAtom < ' tcx > {
13821379 #[ inline( always) ]
13831380 fn to_predicate ( & self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1381+ debug_assert ! ( !self . has_escaping_bound_vars( ) , "excaping bound vars for {:?}" , self ) ;
13841382 tcx. mk_predicate ( ty:: PredicateKind :: Atom ( * self ) )
13851383 }
13861384}
@@ -1408,9 +1406,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
14081406 ty:: PredicateAtom :: Trait ( pred, self . constness ) . to_predicate ( tcx)
14091407 } else {
14101408 ty:: PredicateKind :: ForAll (
1411- self . value . map_bound ( |pred| {
1412- ty:: PredicateAtom :: Trait ( pred, self . constness ) . to_predicate ( tcx)
1413- } ) ,
1409+ self . value . map_bound ( |pred| ty:: PredicateAtom :: Trait ( pred, self . constness ) ) ,
14141410 )
14151411 . to_predicate ( tcx)
14161412 }
@@ -1423,9 +1419,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
14231419 PredicateAtom :: RegionOutlives ( outlives) . to_predicate ( tcx)
14241420 } else {
14251421 ty:: PredicateKind :: ForAll (
1426- self . map_bound ( |outlives| {
1427- PredicateAtom :: RegionOutlives ( outlives) . to_predicate ( tcx)
1428- } ) ,
1422+ self . map_bound ( |outlives| PredicateAtom :: RegionOutlives ( outlives) ) ,
14291423 )
14301424 . to_predicate ( tcx)
14311425 }
@@ -1438,7 +1432,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
14381432 PredicateAtom :: TypeOutlives ( outlives) . to_predicate ( tcx)
14391433 } else {
14401434 ty:: PredicateKind :: ForAll (
1441- self . map_bound ( |outlives| PredicateAtom :: TypeOutlives ( outlives) . to_predicate ( tcx ) ) ,
1435+ self . map_bound ( |outlives| PredicateAtom :: TypeOutlives ( outlives) ) ,
14421436 )
14431437 . to_predicate ( tcx)
14441438 }
@@ -1450,10 +1444,8 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
14501444 if let Some ( proj) = self . no_bound_vars ( ) {
14511445 PredicateAtom :: Projection ( proj) . to_predicate ( tcx)
14521446 } else {
1453- ty:: PredicateKind :: ForAll (
1454- self . map_bound ( |proj| PredicateAtom :: Projection ( proj) . to_predicate ( tcx) ) ,
1455- )
1456- . to_predicate ( tcx)
1447+ ty:: PredicateKind :: ForAll ( self . map_bound ( |proj| PredicateAtom :: Projection ( proj) ) )
1448+ . to_predicate ( tcx)
14571449 }
14581450 }
14591451}
0 commit comments