@@ -1042,7 +1042,30 @@ impl<'tcx> Predicate<'tcx> {
1042
1042
}
1043
1043
1044
1044
/// Skips `PredicateKind::ForAll`.
1045
- pub fn ignore_qualifiers ( self , tcx : TyCtxt < ' tcx > ) -> Binder < Predicate < ' tcx > > {
1045
+ pub fn ignore_qualifiers ( self ) -> Binder < Predicate < ' tcx > > {
1046
+ match self . kind ( ) {
1047
+ & PredicateKind :: ForAll ( binder) => binder,
1048
+ ty:: PredicateKind :: Projection ( ..)
1049
+ | ty:: PredicateKind :: Trait ( ..)
1050
+ | ty:: PredicateKind :: Subtype ( ..)
1051
+ | ty:: PredicateKind :: WellFormed ( ..)
1052
+ | ty:: PredicateKind :: ObjectSafe ( ..)
1053
+ | ty:: PredicateKind :: ClosureKind ( ..)
1054
+ | ty:: PredicateKind :: TypeOutlives ( ..)
1055
+ | ty:: PredicateKind :: ConstEvaluatable ( ..)
1056
+ | ty:: PredicateKind :: ConstEquate ( ..)
1057
+ | ty:: PredicateKind :: RegionOutlives ( ..) => Binder :: dummy ( self ) ,
1058
+ }
1059
+ }
1060
+
1061
+ /// Skips `PredicateKind::ForAll`, while allowing for unbound variables.
1062
+ ///
1063
+ /// This method requires the `TyCtxt` as it has to shift the unbound variables
1064
+ /// outwards.
1065
+ ///
1066
+ /// Do not use this method if you may end up just skipping the binder, as this
1067
+ /// would leave the unbound variables at an incorrect binding level.
1068
+ pub fn ignore_qualifiers_with_unbound_vars ( self , tcx : TyCtxt < ' tcx > ) -> Binder < Predicate < ' tcx > > {
1046
1069
match self . kind ( ) {
1047
1070
& PredicateKind :: ForAll ( binder) => binder,
1048
1071
ty:: PredicateKind :: Projection ( ..)
@@ -1218,7 +1241,7 @@ impl<'tcx> Predicate<'tcx> {
1218
1241
// from the substitution and the value being substituted into, and
1219
1242
// this trick achieves that).
1220
1243
let substs = trait_ref. skip_binder ( ) . substs ;
1221
- let pred = * self . ignore_qualifiers ( tcx ) . skip_binder ( ) ;
1244
+ let pred = * self . ignore_qualifiers ( ) . skip_binder ( ) ;
1222
1245
let new = pred. subst ( tcx, substs) ;
1223
1246
if new != pred { new. potentially_qualified ( tcx, PredicateKind :: ForAll ) } else { self }
1224
1247
}
@@ -1419,8 +1442,8 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
1419
1442
}
1420
1443
1421
1444
impl < ' tcx > Predicate < ' tcx > {
1422
- pub fn to_opt_poly_trait_ref ( self , tcx : TyCtxt < ' tcx > ) -> Option < PolyTraitRef < ' tcx > > {
1423
- self . ignore_qualifiers ( tcx )
1445
+ pub fn to_opt_poly_trait_ref ( self ) -> Option < PolyTraitRef < ' tcx > > {
1446
+ self . ignore_qualifiers ( )
1424
1447
. map_bound ( |pred| match pred. kind ( ) {
1425
1448
& PredicateKind :: Trait ( ref t, _) => Some ( t. trait_ref ) ,
1426
1449
PredicateKind :: Projection ( ..)
@@ -1437,11 +1460,8 @@ impl<'tcx> Predicate<'tcx> {
1437
1460
. transpose ( )
1438
1461
}
1439
1462
1440
- pub fn to_opt_type_outlives (
1441
- self ,
1442
- tcx : TyCtxt < ' tcx > ,
1443
- ) -> Option < PolyTypeOutlivesPredicate < ' tcx > > {
1444
- self . ignore_qualifiers ( tcx)
1463
+ pub fn to_opt_type_outlives ( self ) -> Option < PolyTypeOutlivesPredicate < ' tcx > > {
1464
+ self . ignore_qualifiers ( )
1445
1465
. map_bound ( |pred| match pred. kind ( ) {
1446
1466
& PredicateKind :: TypeOutlives ( data) => Some ( data) ,
1447
1467
PredicateKind :: Trait ( ..)
0 commit comments