Skip to content

Commit af3b1cb

Browse files
committed
Change potentially_qualified to be defined on Binder<PredicateAtom>
1 parent e4297ba commit af3b1cb

File tree

4 files changed

+41
-27
lines changed

4 files changed

+41
-27
lines changed

compiler/rustc_infer/src/infer/canonical/query_response.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
525525
result_subst: &'a CanonicalVarValues<'tcx>,
526526
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
527527
unsubstituted_region_constraints.iter().map(move |&constraint| {
528-
let ty::OutlivesPredicate(k1, r2) =
529-
substitute_value(self.tcx, result_subst, constraint).skip_binder();
528+
let predicate = substitute_value(self.tcx, result_subst, constraint);
529+
let ty::OutlivesPredicate(k1, r2) = predicate.skip_binder();
530530

531-
let predicate = match k1.unpack() {
531+
let atom = match k1.unpack() {
532532
GenericArgKind::Lifetime(r1) => {
533533
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
534534
}
@@ -540,8 +540,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
540540
// encounter this branch.
541541
span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
542542
}
543-
}
544-
.potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
543+
};
544+
let predicate =
545+
predicate.rebind(atom).potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
545546

546547
Obligation::new(cause.clone(), param_env, predicate)
547548
})

compiler/rustc_middle/src/ty/mod.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1149,17 +1149,16 @@ pub enum PredicateAtom<'tcx> {
11491149
TypeWellFormedFromEnv(Ty<'tcx>),
11501150
}
11511151

1152-
impl<'tcx> PredicateAtom<'tcx> {
1152+
impl<'tcx> Binder<PredicateAtom<'tcx>> {
11531153
/// Wraps `self` with the given qualifier if this predicate has any unbound variables.
11541154
pub fn potentially_quantified(
11551155
self,
11561156
tcx: TyCtxt<'tcx>,
11571157
qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>,
11581158
) -> 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),
11631162
}
11641163
.to_predicate(tcx)
11651164
}
@@ -1252,7 +1251,11 @@ impl<'tcx> Predicate<'tcx> {
12521251
let substs = trait_ref.skip_binder().substs;
12531252
let pred = self.skip_binders();
12541253
let new = pred.subst(tcx, substs);
1255-
if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self }
1254+
if new != pred {
1255+
trait_ref.rebind(new).potentially_quantified(tcx, PredicateKind::ForAll)
1256+
} else {
1257+
self
1258+
}
12561259
}
12571260
}
12581261

@@ -1403,28 +1406,29 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
14031406

14041407
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
14051408
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1406-
PredicateAtom::Trait(self.value.skip_binder(), self.constness)
1409+
self.value
1410+
.map_bound(|value| PredicateAtom::Trait(value, self.constness))
14071411
.potentially_quantified(tcx, PredicateKind::ForAll)
14081412
}
14091413
}
14101414

14111415
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
14121416
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1413-
PredicateAtom::RegionOutlives(self.skip_binder())
1417+
self.map_bound(|value| PredicateAtom::RegionOutlives(value))
14141418
.potentially_quantified(tcx, PredicateKind::ForAll)
14151419
}
14161420
}
14171421

14181422
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
14191423
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1420-
PredicateAtom::TypeOutlives(self.skip_binder())
1424+
self.map_bound(|value| PredicateAtom::TypeOutlives(value))
14211425
.potentially_quantified(tcx, PredicateKind::ForAll)
14221426
}
14231427
}
14241428

14251429
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
14261430
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1427-
PredicateAtom::Projection(self.skip_binder())
1431+
self.map_bound(|value| PredicateAtom::Projection(value))
14281432
.potentially_quantified(tcx, PredicateKind::ForAll)
14291433
}
14301434
}

compiler/rustc_typeck/src/collect.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1919,10 +1919,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19191919
} else {
19201920
let span = bound_pred.bounded_ty.span;
19211921
let re_root_empty = tcx.lifetimes.re_root_empty;
1922-
let predicate = ty::OutlivesPredicate(ty, re_root_empty);
1922+
let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
1923+
ty::OutlivesPredicate(ty, re_root_empty),
1924+
));
19231925
predicates.insert((
1924-
ty::PredicateAtom::TypeOutlives(predicate)
1925-
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
1926+
predicate.potentially_quantified(tcx, ty::PredicateKind::ForAll),
19261927
span,
19271928
));
19281929
}
@@ -1965,8 +1966,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19651966
&hir::GenericBound::Outlives(ref lifetime) => {
19661967
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
19671968
predicates.insert((
1968-
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region))
1969-
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
1969+
ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
1970+
ty::OutlivesPredicate(ty, region),
1971+
))
1972+
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
19701973
lifetime.span,
19711974
));
19721975
}
@@ -1983,7 +1986,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
19831986
}
19841987
_ => bug!(),
19851988
};
1986-
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2));
1989+
let pred = ty::Binder::dummy(ty::PredicateAtom::RegionOutlives(
1990+
ty::OutlivesPredicate(r1, r2),
1991+
));
19871992

19881993
(pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
19891994
}))
@@ -2233,8 +2238,10 @@ fn predicates_from_bound<'tcx>(
22332238
}
22342239
hir::GenericBound::Outlives(ref lifetime) => {
22352240
let region = astconv.ast_region_to_region(lifetime, None);
2236-
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
2237-
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
2241+
let pred = ty::Binder::dummy(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
2242+
param_ty, region,
2243+
)))
2244+
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
22382245
vec![(pred, lifetime.span)]
22392246
}
22402247
}

compiler/rustc_typeck/src/outlives/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
8989
|(ty::OutlivesPredicate(kind1, region2), &span)| {
9090
match kind1.unpack() {
9191
GenericArgKind::Type(ty1) => Some((
92-
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
93-
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
92+
ty::Binder::dummy(ty::PredicateAtom::TypeOutlives(
93+
ty::OutlivesPredicate(ty1, region2),
94+
))
95+
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
9496
span,
9597
)),
9698
GenericArgKind::Lifetime(region1) => Some((
97-
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
98-
region1, region2,
99+
ty::Binder::dummy(ty::PredicateAtom::RegionOutlives(
100+
ty::OutlivesPredicate(region1, region2),
99101
))
100102
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
101103
span,

0 commit comments

Comments
 (0)