add reuse_or_mk_predicate
This commit is contained in:
parent
d030752f63
commit
52af82bdb9
@ -526,7 +526,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
||||
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
|
||||
unsubstituted_region_constraints.iter().map(move |constraint| {
|
||||
let ty::OutlivesPredicate(k1, r2) =
|
||||
*substitute_value(self.tcx, result_subst, constraint).skip_binder();
|
||||
substitute_value(self.tcx, result_subst, constraint).skip_binder();
|
||||
|
||||
let predicate = match k1.unpack() {
|
||||
GenericArgKind::Lifetime(r1) => {
|
||||
|
@ -10,11 +10,10 @@ pub fn anonymize_predicate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
pred: ty::Predicate<'tcx>,
|
||||
) -> ty::Predicate<'tcx> {
|
||||
let kind = pred.kind();
|
||||
match kind {
|
||||
match pred.kind() {
|
||||
ty::PredicateKind::ForAll(binder) => {
|
||||
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
|
||||
if new != *kind { new.to_predicate(tcx) } else { pred }
|
||||
tcx.reuse_or_mk_predicate(pred, new)
|
||||
}
|
||||
ty::PredicateKind::Trait(_, _)
|
||||
| ty::PredicateKind::RegionOutlives(_)
|
||||
|
@ -2132,11 +2132,20 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
|
||||
pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
|
||||
let inner = self.interners.intern_predicate(kind);
|
||||
Predicate { inner }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reuse_or_mk_predicate(
|
||||
self,
|
||||
pred: Predicate<'tcx>,
|
||||
kind: PredicateKind<'tcx>,
|
||||
) -> Predicate<'tcx> {
|
||||
if *pred.kind() != kind { self.mk_predicate(kind) } else { pred }
|
||||
}
|
||||
|
||||
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
ast::IntTy::Isize => self.types.isize,
|
||||
|
@ -201,7 +201,7 @@ impl FlagComputation {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_predicate(&mut self, pred: &ty::Predicate<'_>) {
|
||||
fn add_predicate(&mut self, pred: ty::Predicate<'_>) {
|
||||
self.add_flags(pred.inner.flags);
|
||||
self.add_exclusive_binder(pred.inner.outer_exclusive_binder);
|
||||
}
|
||||
@ -223,7 +223,7 @@ impl FlagComputation {
|
||||
self.add_ty(a);
|
||||
self.add_ty(b);
|
||||
}
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
|
||||
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
|
||||
self.add_projection_ty(projection_ty);
|
||||
self.add_ty(ty);
|
||||
}
|
||||
|
@ -1252,7 +1252,7 @@ impl<'tcx> Predicate<'tcx> {
|
||||
// from the substitution and the value being substituted into, and
|
||||
// this trick achieves that).
|
||||
let substs = trait_ref.skip_binder().substs;
|
||||
let pred = *self.ignore_quantifiers().skip_binder();
|
||||
let pred = self.ignore_quantifiers().skip_binder();
|
||||
let new = pred.subst(tcx, substs);
|
||||
if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self }
|
||||
}
|
||||
|
@ -1000,7 +1000,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let new = ty::PredicateKind::super_fold_with(&self.inner.kind, folder);
|
||||
if new != self.inner.kind { folder.tcx().mk_predicate(new) } else { *self }
|
||||
folder.tcx().reuse_or_mk_predicate(*self, new)
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
|
@ -89,7 +89,7 @@ where
|
||||
&ty::PredicateKind::ForAll(pred) => {
|
||||
// This visitor does not care about bound regions as we only
|
||||
// look at `DefId`s.
|
||||
self.visit_predicate(*pred.skip_binder())
|
||||
self.visit_predicate(pred.skip_binder())
|
||||
}
|
||||
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
|
||||
self.visit_trait(trait_ref)
|
||||
|
@ -88,7 +88,7 @@ pub fn predicate_obligations<'a, 'tcx>(
|
||||
infcx: &InferCtxt<'a, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
body_id: hir::HirId,
|
||||
predicate: &'_ ty::Predicate<'tcx>,
|
||||
predicate: ty::Predicate<'tcx>,
|
||||
span: Span,
|
||||
) -> Vec<traits::PredicateObligation<'tcx>> {
|
||||
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };
|
||||
|
@ -828,7 +828,7 @@ fn check_where_clauses<'tcx, 'fcx>(
|
||||
debug!("check_where_clauses: predicates={:?}", predicates.predicates);
|
||||
assert_eq!(predicates.predicates.len(), predicates.spans.len());
|
||||
let wf_obligations =
|
||||
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(p, &sp)| {
|
||||
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(&p, &sp)| {
|
||||
traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, sp)
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user