From 4b193cb92aee0d57dc7bfcf5e22e8e168eec6975 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 17 Sep 2018 13:44:20 -0400 Subject: [PATCH] propagate the `compare_ty` fn further up --- src/librustc/infer/outlives/verify.rs | 35 +++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/librustc/infer/outlives/verify.rs b/src/librustc/infer/outlives/verify.rs index 2390ea55c447..2275d7001461 100644 --- a/src/librustc/infer/outlives/verify.rs +++ b/src/librustc/infer/outlives/verify.rs @@ -102,23 +102,15 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> { self.declared_projection_bounds_from_trait(projection_ty) } - pub fn projection_bound( - &self, - projection_ty: ty::ProjectionTy<'tcx>, - ) -> VerifyBound<'tcx> { - debug!( - "projection_bound(projection_ty={:?})", - projection_ty - ); + pub fn projection_bound(&self, projection_ty: ty::ProjectionTy<'tcx>) -> VerifyBound<'tcx> { + debug!("projection_bound(projection_ty={:?})", projection_ty); // Search the env for where clauses like `P: 'a`. let mut declared_bounds = self.declared_generic_bounds_from_env(GenericKind::Projection(projection_ty)); // Extend with bounds that we can find from the trait. - declared_bounds.extend( - self.projection_declared_bounds_from_trait(projection_ty) - ); + declared_bounds.extend(self.projection_declared_bounds_from_trait(projection_ty)); debug!("projection_bound: declared_bounds = {:?}", declared_bounds); @@ -158,6 +150,14 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> { fn declared_generic_bounds_from_env( &self, generic: GenericKind<'tcx>, + ) -> Vec> { + let generic_ty = generic.to_ty(self.tcx); + self.declared_generic_bounds_from_env_with_compare_fn(|ty| ty == generic_ty) + } + + fn declared_generic_bounds_from_env_with_compare_fn( + &self, + compare_ty: impl Fn(Ty<'tcx>) -> bool, ) -> Vec> { let tcx = self.tcx; @@ -167,12 +167,8 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> { // dubious for projections, but it will work for simple cases // like `T` and `T::Item`. It may not work as well for things // like `>::Item`. - let generic_ty = generic.to_ty(tcx); let c_b = self.param_env.caller_bounds; - let mut param_bounds = self.collect_outlives_from_predicate_list( - |ty| ty == generic_ty, - c_b, - ); + let mut param_bounds = self.collect_outlives_from_predicate_list(&compare_ty, c_b); // Next, collect regions we scraped from the well-formedness // constraints in the fn signature. To do that, we walk the list @@ -186,8 +182,11 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> { // well-formed, then, A must be lower-generic by `'a`, but we // don't know that this holds from first principles. for &(r, p) in self.region_bound_pairs { - debug!("generic={:?} p={:?}", generic, p); - if generic == p { + debug!( + "declared_generic_bounds_from_env_with_compare_fn: region_bound_pair = {:?}", + (r, p) + ); + if compare_ty(p.to_ty(tcx)) { param_bounds.push(r); } }