1
Fork 0

Change potentially_qualified to be defined on Binder<PredicateAtom>

This commit is contained in:
Jack Huey 2020-12-16 21:13:29 -05:00
parent e4297ba39c
commit af3b1cb0b5
4 changed files with 41 additions and 27 deletions

View file

@ -525,10 +525,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
result_subst: &'a CanonicalVarValues<'tcx>, result_subst: &'a CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> { ) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
unsubstituted_region_constraints.iter().map(move |&constraint| { unsubstituted_region_constraints.iter().map(move |&constraint| {
let ty::OutlivesPredicate(k1, r2) = let predicate = substitute_value(self.tcx, result_subst, constraint);
substitute_value(self.tcx, result_subst, constraint).skip_binder(); let ty::OutlivesPredicate(k1, r2) = predicate.skip_binder();
let predicate = match k1.unpack() { let atom = match k1.unpack() {
GenericArgKind::Lifetime(r1) => { GenericArgKind::Lifetime(r1) => {
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2)) ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
} }
@ -540,8 +540,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// encounter this branch. // encounter this branch.
span_bug!(cause.span, "unexpected const outlives {:?}", constraint); span_bug!(cause.span, "unexpected const outlives {:?}", constraint);
} }
} };
.potentially_quantified(self.tcx, ty::PredicateKind::ForAll); let predicate =
predicate.rebind(atom).potentially_quantified(self.tcx, ty::PredicateKind::ForAll);
Obligation::new(cause.clone(), param_env, predicate) Obligation::new(cause.clone(), param_env, predicate)
}) })

View file

@ -1149,17 +1149,16 @@ pub enum PredicateAtom<'tcx> {
TypeWellFormedFromEnv(Ty<'tcx>), TypeWellFormedFromEnv(Ty<'tcx>),
} }
impl<'tcx> PredicateAtom<'tcx> { impl<'tcx> Binder<PredicateAtom<'tcx>> {
/// Wraps `self` with the given qualifier if this predicate has any unbound variables. /// Wraps `self` with the given qualifier if this predicate has any unbound variables.
pub fn potentially_quantified( pub fn potentially_quantified(
self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>, qualifier: impl FnOnce(Binder<PredicateAtom<'tcx>>) -> PredicateKind<'tcx>,
) -> Predicate<'tcx> { ) -> Predicate<'tcx> {
if self.has_escaping_bound_vars() { match self.no_bound_vars() {
qualifier(Binder::bind(self)) Some(atom) => PredicateKind::Atom(atom),
} else { None => qualifier(self),
PredicateKind::Atom(self)
} }
.to_predicate(tcx) .to_predicate(tcx)
} }
@ -1252,7 +1251,11 @@ impl<'tcx> Predicate<'tcx> {
let substs = trait_ref.skip_binder().substs; let substs = trait_ref.skip_binder().substs;
let pred = self.skip_binders(); let pred = self.skip_binders();
let new = pred.subst(tcx, substs); let new = pred.subst(tcx, substs);
if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self } if new != pred {
trait_ref.rebind(new).potentially_quantified(tcx, PredicateKind::ForAll)
} else {
self
}
} }
} }
@ -1403,28 +1406,29 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitPredicate<'tcx>> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateAtom::Trait(self.value.skip_binder(), self.constness) self.value
.map_bound(|value| PredicateAtom::Trait(value, self.constness))
.potentially_quantified(tcx, PredicateKind::ForAll) .potentially_quantified(tcx, PredicateKind::ForAll)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateAtom::RegionOutlives(self.skip_binder()) self.map_bound(|value| PredicateAtom::RegionOutlives(value))
.potentially_quantified(tcx, PredicateKind::ForAll) .potentially_quantified(tcx, PredicateKind::ForAll)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateAtom::TypeOutlives(self.skip_binder()) self.map_bound(|value| PredicateAtom::TypeOutlives(value))
.potentially_quantified(tcx, PredicateKind::ForAll) .potentially_quantified(tcx, PredicateKind::ForAll)
} }
} }
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
PredicateAtom::Projection(self.skip_binder()) self.map_bound(|value| PredicateAtom::Projection(value))
.potentially_quantified(tcx, PredicateKind::ForAll) .potentially_quantified(tcx, PredicateKind::ForAll)
} }
} }

View file

@ -1919,10 +1919,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
} else { } else {
let span = bound_pred.bounded_ty.span; let span = bound_pred.bounded_ty.span;
let re_root_empty = tcx.lifetimes.re_root_empty; let re_root_empty = tcx.lifetimes.re_root_empty;
let predicate = ty::OutlivesPredicate(ty, re_root_empty); let predicate = ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
ty::OutlivesPredicate(ty, re_root_empty),
));
predicates.insert(( predicates.insert((
ty::PredicateAtom::TypeOutlives(predicate) predicate.potentially_quantified(tcx, ty::PredicateKind::ForAll),
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
span, span,
)); ));
} }
@ -1965,7 +1966,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
&hir::GenericBound::Outlives(ref lifetime) => { &hir::GenericBound::Outlives(ref lifetime) => {
let region = AstConv::ast_region_to_region(&icx, lifetime, None); let region = AstConv::ast_region_to_region(&icx, lifetime, None);
predicates.insert(( predicates.insert((
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty, region)) ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
ty::OutlivesPredicate(ty, region),
))
.potentially_quantified(tcx, ty::PredicateKind::ForAll), .potentially_quantified(tcx, ty::PredicateKind::ForAll),
lifetime.span, lifetime.span,
)); ));
@ -1983,7 +1986,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
} }
_ => bug!(), _ => bug!(),
}; };
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2)); let pred = ty::Binder::dummy(ty::PredicateAtom::RegionOutlives(
ty::OutlivesPredicate(r1, r2),
));
(pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span) (pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
})) }))
@ -2233,7 +2238,9 @@ fn predicates_from_bound<'tcx>(
} }
hir::GenericBound::Outlives(ref lifetime) => { hir::GenericBound::Outlives(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None); let region = astconv.ast_region_to_region(lifetime, None);
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region)) let pred = ty::Binder::dummy(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
param_ty, region,
)))
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll); .potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
vec![(pred, lifetime.span)] vec![(pred, lifetime.span)]
} }

View file

@ -89,13 +89,15 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|(ty::OutlivesPredicate(kind1, region2), &span)| { |(ty::OutlivesPredicate(kind1, region2), &span)| {
match kind1.unpack() { match kind1.unpack() {
GenericArgKind::Type(ty1) => Some(( GenericArgKind::Type(ty1) => Some((
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2)) ty::Binder::dummy(ty::PredicateAtom::TypeOutlives(
ty::OutlivesPredicate(ty1, region2),
))
.potentially_quantified(tcx, ty::PredicateKind::ForAll), .potentially_quantified(tcx, ty::PredicateKind::ForAll),
span, span,
)), )),
GenericArgKind::Lifetime(region1) => Some(( GenericArgKind::Lifetime(region1) => Some((
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate( ty::Binder::dummy(ty::PredicateAtom::RegionOutlives(
region1, region2, ty::OutlivesPredicate(region1, region2),
)) ))
.potentially_quantified(tcx, ty::PredicateKind::ForAll), .potentially_quantified(tcx, ty::PredicateKind::ForAll),
span, span,