diff --git a/src/librustc_infer/infer/canonical/query_response.rs b/src/librustc_infer/infer/canonical/query_response.rs index 1a54fa0657c..a6229e61ae7 100644 --- a/src/librustc_infer/infer/canonical/query_response.rs +++ b/src/librustc_infer/infer/canonical/query_response.rs @@ -526,7 +526,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { ) -> impl Iterator> + '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) => { diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index cb2f2ca0e92..0d343be2c26 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -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(_) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 1e7fceb8e22..eeb58a0c55a 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -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, diff --git a/src/librustc_middle/ty/flags.rs b/src/librustc_middle/ty/flags.rs index c8c8475b056..4b1f970edb0 100644 --- a/src/librustc_middle/ty/flags.rs +++ b/src/librustc_middle/ty/flags.rs @@ -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); } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index dd74fbc9457..c8ad8ae10dc 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -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 } } diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 55fab499905..e6237853f21 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -1000,7 +1000,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { fn super_fold_with>(&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>(&self, visitor: &mut V) -> bool { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 3591a707ac0..223e92e0482 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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) diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index ffafbabddfc..afa2270b7af 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -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> { let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None }; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 80f03e2211a..dabae6cbc41 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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) });