1
Fork 0

Generalize a helper to be useful for types other than projections

This commit is contained in:
Oli Scherer 2022-05-18 15:17:58 +00:00
parent 96b819a456
commit 4d4cc4fe53
2 changed files with 7 additions and 7 deletions

View file

@ -347,11 +347,12 @@ where
debug!(?trait_bounds); debug!(?trait_bounds);
let generic = GenericKind::Projection(projection_ty);
// Compute the bounds we can derive from the environment. This // Compute the bounds we can derive from the environment. This
// is an "approximate" match -- in some cases, these bounds // is an "approximate" match -- in some cases, these bounds
// may not apply. // may not apply.
let mut approx_env_bounds = let mut approx_env_bounds = self.verify_bound.approx_declared_bounds_from_env(generic);
self.verify_bound.projection_approx_declared_bounds_from_env(projection_ty);
debug!(?approx_env_bounds); debug!(?approx_env_bounds);
// Remove outlives bounds that we get from the environment but // Remove outlives bounds that we get from the environment but
@ -436,7 +437,6 @@ where
// projection outlive; in some cases, this may add insufficient // projection outlive; in some cases, this may add insufficient
// edges into the inference graph, leading to inference failures // edges into the inference graph, leading to inference failures
// even though a satisfactory solution exists. // even though a satisfactory solution exists.
let generic = GenericKind::Projection(projection_ty);
let verify_bound = self.verify_bound.generic_bound(generic); let verify_bound = self.verify_bound.generic_bound(generic);
debug!("projection_must_outlive: pushing {:?}", verify_bound); debug!("projection_must_outlive: pushing {:?}", verify_bound);
self.delegate.push_verify(origin, generic, region, verify_bound); self.delegate.push_verify(origin, generic, region, verify_bound);

View file

@ -105,11 +105,11 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
/// the clause from the environment only applies if `'0 = 'a`, /// the clause from the environment only applies if `'0 = 'a`,
/// which we don't know yet. But we would still include `'b` in /// which we don't know yet. But we would still include `'b` in
/// this list. /// this list.
pub fn projection_approx_declared_bounds_from_env( pub fn approx_declared_bounds_from_env(
&self, &self,
projection_ty: ty::ProjectionTy<'tcx>, generic: GenericKind<'tcx>,
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> { ) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, 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); let erased_projection_ty = self.tcx.erase_regions(projection_ty);
self.declared_generic_bounds_from_env_for_erased_ty(erased_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`. // Search the env for where clauses like `P: 'a`.
let env_bounds = self let env_bounds = self
.projection_approx_declared_bounds_from_env(projection_ty) .approx_declared_bounds_from_env(GenericKind::Projection(projection_ty))
.into_iter() .into_iter()
.map(|binder| { .map(|binder| {
if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars() && ty == projection_ty_as_ty { if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars() && ty == projection_ty_as_ty {