From 4d4cc4fe53aec2a7f36535c3458aced2fcd2988d Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 18 May 2022 15:17:58 +0000 Subject: [PATCH] Generalize a helper to be useful for types other than projections --- compiler/rustc_infer/src/infer/outlives/obligations.rs | 6 +++--- compiler/rustc_infer/src/infer/outlives/verify.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 3f98168e2573..ec26a10c5362 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -347,11 +347,12 @@ where debug!(?trait_bounds); + let generic = GenericKind::Projection(projection_ty); + // Compute the bounds we can derive from the environment. This // is an "approximate" match -- in some cases, these bounds // may not apply. - let mut approx_env_bounds = - self.verify_bound.projection_approx_declared_bounds_from_env(projection_ty); + let mut approx_env_bounds = self.verify_bound.approx_declared_bounds_from_env(generic); debug!(?approx_env_bounds); // Remove outlives bounds that we get from the environment but @@ -436,7 +437,6 @@ where // projection outlive; in some cases, this may add insufficient // edges into the inference graph, leading to inference failures // even though a satisfactory solution exists. - let generic = GenericKind::Projection(projection_ty); let verify_bound = self.verify_bound.generic_bound(generic); debug!("projection_must_outlive: pushing {:?}", verify_bound); self.delegate.push_verify(origin, generic, region, verify_bound); diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 30ee1229faec..5f1671b4807c 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -105,11 +105,11 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { /// the clause from the environment only applies if `'0 = 'a`, /// which we don't know yet. But we would still include `'b` in /// this list. - pub fn projection_approx_declared_bounds_from_env( + pub fn approx_declared_bounds_from_env( &self, - projection_ty: ty::ProjectionTy<'tcx>, + generic: GenericKind<'tcx>, ) -> Vec, ty::Region<'tcx>>>> { - let projection_ty = GenericKind::Projection(projection_ty).to_ty(self.tcx); + let projection_ty = generic.to_ty(self.tcx); let erased_projection_ty = self.tcx.erase_regions(projection_ty); self.declared_generic_bounds_from_env_for_erased_ty(erased_projection_ty) } @@ -125,7 +125,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // Search the env for where clauses like `P: 'a`. let env_bounds = self - .projection_approx_declared_bounds_from_env(projection_ty) + .approx_declared_bounds_from_env(GenericKind::Projection(projection_ty)) .into_iter() .map(|binder| { if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars() && ty == projection_ty_as_ty {