Skip to content

Commit 52af82b

Browse files
committed
add reuse_or_mk_predicate
1 parent d030752 commit 52af82b

File tree

9 files changed

+20
-12
lines changed

9 files changed

+20
-12
lines changed

src/librustc_infer/infer/canonical/query_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
526526
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
527527
unsubstituted_region_constraints.iter().map(move |constraint| {
528528
let ty::OutlivesPredicate(k1, r2) =
529-
*substitute_value(self.tcx, result_subst, constraint).skip_binder();
529+
substitute_value(self.tcx, result_subst, constraint).skip_binder();
530530

531531
let predicate = match k1.unpack() {
532532
GenericArgKind::Lifetime(r1) => {

src/librustc_infer/traits/util.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
1111
pred: ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
13-
let kind = pred.kind();
14-
match kind {
13+
match pred.kind() {
1514
ty::PredicateKind::ForAll(binder) => {
1615
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
17-
if new != *kind { new.to_predicate(tcx) } else { pred }
16+
tcx.reuse_or_mk_predicate(pred, new)
1817
}
1918
ty::PredicateKind::Trait(_, _)
2019
| ty::PredicateKind::RegionOutlives(_)

src/librustc_middle/ty/context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,11 +2132,20 @@ impl<'tcx> TyCtxt<'tcx> {
21322132
}
21332133

21342134
#[inline]
2135-
pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
2135+
pub fn mk_predicate(self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
21362136
let inner = self.interners.intern_predicate(kind);
21372137
Predicate { inner }
21382138
}
21392139

2140+
#[inline]
2141+
pub fn reuse_or_mk_predicate(
2142+
self,
2143+
pred: Predicate<'tcx>,
2144+
kind: PredicateKind<'tcx>,
2145+
) -> Predicate<'tcx> {
2146+
if *pred.kind() != kind { self.mk_predicate(kind) } else { pred }
2147+
}
2148+
21402149
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
21412150
match tm {
21422151
ast::IntTy::Isize => self.types.isize,

src/librustc_middle/ty/flags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl FlagComputation {
201201
}
202202
}
203203

204-
fn add_predicate(&mut self, pred: &ty::Predicate<'_>) {
204+
fn add_predicate(&mut self, pred: ty::Predicate<'_>) {
205205
self.add_flags(pred.inner.flags);
206206
self.add_exclusive_binder(pred.inner.outer_exclusive_binder);
207207
}
@@ -223,7 +223,7 @@ impl FlagComputation {
223223
self.add_ty(a);
224224
self.add_ty(b);
225225
}
226-
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
226+
&ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
227227
self.add_projection_ty(projection_ty);
228228
self.add_ty(ty);
229229
}

src/librustc_middle/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ impl<'tcx> Predicate<'tcx> {
12521252
// from the substitution and the value being substituted into, and
12531253
// this trick achieves that).
12541254
let substs = trait_ref.skip_binder().substs;
1255-
let pred = *self.ignore_quantifiers().skip_binder();
1255+
let pred = self.ignore_quantifiers().skip_binder();
12561256
let new = pred.subst(tcx, substs);
12571257
if new != pred { new.potentially_quantified(tcx, PredicateKind::ForAll) } else { self }
12581258
}

src/librustc_middle/ty/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
10001000
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
10011001
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
10021002
let new = ty::PredicateKind::super_fold_with(&self.inner.kind, folder);
1003-
if new != self.inner.kind { folder.tcx().mk_predicate(new) } else { *self }
1003+
folder.tcx().reuse_or_mk_predicate(*self, new)
10041004
}
10051005

10061006
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {

src/librustc_privacy/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
&ty::PredicateKind::ForAll(pred) => {
9090
// This visitor does not care about bound regions as we only
9191
// look at `DefId`s.
92-
self.visit_predicate(*pred.skip_binder())
92+
self.visit_predicate(pred.skip_binder())
9393
}
9494
&ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
9595
self.visit_trait(trait_ref)

src/librustc_trait_selection/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn predicate_obligations<'a, 'tcx>(
8888
infcx: &InferCtxt<'a, 'tcx>,
8989
param_env: ty::ParamEnv<'tcx>,
9090
body_id: hir::HirId,
91-
predicate: &'_ ty::Predicate<'tcx>,
91+
predicate: ty::Predicate<'tcx>,
9292
span: Span,
9393
) -> Vec<traits::PredicateObligation<'tcx>> {
9494
let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None };

src/librustc_typeck/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ fn check_where_clauses<'tcx, 'fcx>(
828828
debug!("check_where_clauses: predicates={:?}", predicates.predicates);
829829
assert_eq!(predicates.predicates.len(), predicates.spans.len());
830830
let wf_obligations =
831-
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(p, &sp)| {
831+
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(&p, &sp)| {
832832
traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, sp)
833833
});
834834

0 commit comments

Comments
 (0)