Skip to content

Commit 615c9e8

Browse files
committed
Inline substitution logic into declared_region_bounds
1 parent a8c9784 commit 615c9e8

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

compiler/rustc_infer/src/infer/outlives/obligations.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ where
390390
// Compute the bounds we can derive from the trait definition.
391391
// These are guaranteed to apply, no matter the inference
392392
// results.
393-
let trait_bounds: Vec<_> = self.verify_bound.bounds(def_id, substs).collect();
393+
let trait_bounds: Vec<_> =
394+
self.verify_bound.declared_region_bounds(def_id, substs).collect();
394395

395396
debug!(?trait_bounds);
396397

@@ -413,7 +414,7 @@ where
413414
// will be invoked with `['b => ^1]` and so we will get `^1` returned.
414415
let bound = bound_outlives.skip_binder();
415416
let (def_id, substs) = filter(bound.0);
416-
self.verify_bound.bounds(def_id, substs).all(|r| r != bound.1)
417+
self.verify_bound.declared_region_bounds(def_id, substs).all(|r| r != bound.1)
417418
});
418419

419420
// If declared bounds list is empty, the only applicable rule is

compiler/rustc_infer/src/infer/outlives/verify.rs

+8-27
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::infer::outlives::components::{compute_components_recursive, Component
22
use crate::infer::outlives::env::RegionBoundPairs;
33
use crate::infer::region_constraints::VerifyIfEq;
44
use crate::infer::{GenericKind, VerifyBound};
5-
use rustc_data_structures::captures::Captures;
65
use rustc_data_structures::sso::SsoHashSet;
76
use rustc_hir::def_id::DefId;
87
use rustc_middle::ty::GenericArg;
@@ -128,7 +127,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
128127
}
129128
});
130129
// Extend with bounds that we can find from the trait.
131-
let trait_bounds = self.bounds(def_id, substs).map(|r| VerifyBound::OutlivedBy(r));
130+
let trait_bounds =
131+
self.declared_region_bounds(def_id, substs).map(|r| VerifyBound::OutlivedBy(r));
132132

133133
// see the extensive comment in projection_must_outlive
134134
let recursive_bound = {
@@ -279,30 +279,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
279279
/// }
280280
/// ```
281281
///
282-
/// then this function would return `'x`. This is subject to the
283-
/// limitations around higher-ranked bounds described in
284-
/// `declared_region_bounds`.
285-
#[instrument(level = "debug", skip(self))]
286-
pub fn bounds(
287-
&self,
288-
def_id: DefId,
289-
substs: SubstsRef<'tcx>,
290-
) -> impl Iterator<Item = ty::Region<'tcx>> + 'cx + Captures<'tcx> {
291-
let tcx = self.tcx;
292-
self.declared_region_bounds(def_id).map(move |r| EarlyBinder(r).subst(tcx, substs))
293-
}
294-
295-
/// Given the `DefId` of an associated item, returns any region
296-
/// bounds attached to that associated item from the trait definition.
297-
///
298-
/// For example:
299-
///
300-
/// ```rust
301-
/// trait Foo<'a> {
302-
/// type Bar: 'a;
303-
/// }
304-
/// ```
305-
///
306282
/// If we were given the `DefId` of `Foo::Bar`, we would return
307283
/// `'a`. You could then apply the substitutions from the
308284
/// projection to convert this into your namespace. This also
@@ -322,7 +298,11 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
322298
///
323299
/// This is for simplicity, and because we are not really smart
324300
/// enough to cope with such bounds anywhere.
325-
fn declared_region_bounds(&self, def_id: DefId) -> impl Iterator<Item = ty::Region<'tcx>> {
301+
pub fn declared_region_bounds(
302+
&self,
303+
def_id: DefId,
304+
substs: SubstsRef<'tcx>,
305+
) -> impl Iterator<Item = ty::Region<'tcx>> {
326306
let tcx = self.tcx;
327307
let bounds = tcx.item_bounds(def_id);
328308
trace!("{:#?}", bounds);
@@ -331,6 +311,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
331311
.filter_map(|p| p.to_opt_type_outlives())
332312
.filter_map(|p| p.no_bound_vars())
333313
.map(|b| b.1)
314+
.map(move |r| EarlyBinder(r).subst(tcx, substs))
334315
}
335316

336317
/// Searches through a predicate list for a predicate `T: 'a`.

0 commit comments

Comments
 (0)