Skip to content

Commit

Permalink
add reuse_or_mk_predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Jul 27, 2020
1 parent d030752 commit 52af82b
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_infer/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down
11 changes: 10 additions & 1 deletion src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});

Expand Down

0 comments on commit 52af82b

Please sign in to comment.