From 96b819a456672e50444dcccbfed2435f6b212225 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 18 May 2022 15:09:14 +0000 Subject: [PATCH] Inline a trivial function --- .../src/infer/outlives/obligations.rs | 4 +-- .../rustc_infer/src/infer/outlives/verify.rs | 34 ++++++------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index e8751095428..3f98168e257 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -343,7 +343,7 @@ where // These are guaranteed to apply, no matter the inference // results. let trait_bounds: Vec<_> = - self.verify_bound.projection_declared_bounds_from_trait(projection_ty).collect(); + self.verify_bound.bounds(projection_ty.item_def_id, projection_ty.substs).collect(); debug!(?trait_bounds); @@ -369,7 +369,7 @@ where match *bound.0.kind() { ty::Projection(projection_ty) => self .verify_bound - .projection_declared_bounds_from_trait(projection_ty) + .bounds(projection_ty.item_def_id, projection_ty.substs) .all(|r| r != bound.1), _ => panic!("expected only projection types from env, not {:?}", bound.0), diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index bd7b8a3004f..30ee1229fae 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -6,7 +6,7 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::sso::SsoHashSet; use rustc_hir::def_id::DefId; use rustc_middle::ty::GenericArg; -use rustc_middle::ty::{self, EarlyBinder, OutlivesPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, EarlyBinder, OutlivesPredicate, SubstsRef, Ty, TyCtxt}; use smallvec::smallvec; @@ -114,16 +114,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { self.declared_generic_bounds_from_env_for_erased_ty(erased_projection_ty) } - /// Searches the where-clauses in scope for regions that - /// `projection_ty` is known to outlive. Currently requires an - /// exact match. - pub fn projection_declared_bounds_from_trait( - &self, - projection_ty: ty::ProjectionTy<'tcx>, - ) -> impl Iterator> + 'cx + Captures<'tcx> { - self.declared_projection_bounds_from_trait(projection_ty) - } - #[instrument(level = "debug", skip(self, visited))] fn projection_bound( &self, @@ -151,7 +141,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { // Extend with bounds that we can find from the trait. let trait_bounds = self - .projection_declared_bounds_from_trait(projection_ty) + .bounds(projection_ty.item_def_id, projection_ty.substs) .map(|r| VerifyBound::OutlivedBy(r)); // see the extensive comment in projection_must_outlive @@ -294,15 +284,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { /// /// then this function would return `'x`. This is subject to the /// limitations around higher-ranked bounds described in - /// `region_bounds_declared_on_associated_item`. - fn declared_projection_bounds_from_trait( + /// `declared_region_bounds`. + #[instrument(level = "debug", skip(self))] + pub fn bounds( &self, - projection_ty: ty::ProjectionTy<'tcx>, + def_id: DefId, + substs: SubstsRef<'tcx>, ) -> impl Iterator> + 'cx + Captures<'tcx> { - debug!("projection_bounds(projection_ty={:?})", projection_ty); let tcx = self.tcx; - self.region_bounds_declared_on_associated_item(projection_ty.item_def_id) - .map(move |r| EarlyBinder(r).subst(tcx, projection_ty.substs)) + self.declared_region_bounds(def_id).map(move |r| EarlyBinder(r).subst(tcx, substs)) } /// Given the `DefId` of an associated item, returns any region @@ -335,12 +325,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { /// /// This is for simplicity, and because we are not really smart /// enough to cope with such bounds anywhere. - fn region_bounds_declared_on_associated_item( - &self, - assoc_item_def_id: DefId, - ) -> impl Iterator> { + fn declared_region_bounds(&self, def_id: DefId) -> impl Iterator> { let tcx = self.tcx; - let bounds = tcx.item_bounds(assoc_item_def_id); + let bounds = tcx.item_bounds(def_id); + trace!("{:#?}", bounds); bounds .into_iter() .filter_map(|p| p.to_opt_type_outlives())