Greatly simplify lifetime captures in edition 2024
This commit is contained in:
parent
46420c9607
commit
12e3911d81
84 changed files with 223 additions and 294 deletions
|
@ -8,7 +8,6 @@ use std::ops::ControlFlow;
|
|||
|
||||
use either::Either;
|
||||
use hir::{ClosureKind, Path};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err};
|
||||
|
@ -3530,10 +3529,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
location: Location,
|
||||
mpi: MovePathIndex,
|
||||
) -> (Vec<MoveSite>, Vec<Location>) {
|
||||
fn predecessor_locations<'a, 'tcx>(
|
||||
body: &'a mir::Body<'tcx>,
|
||||
fn predecessor_locations<'tcx>(
|
||||
body: &mir::Body<'tcx>,
|
||||
location: Location,
|
||||
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
|
||||
) -> impl Iterator<Item = Location> {
|
||||
if location.statement_index == 0 {
|
||||
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
|
||||
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::hash::Hash;
|
||||
use std::ops::Index;
|
||||
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
|
@ -147,9 +146,7 @@ impl<'tcx, R> MemberConstraintSet<'tcx, R>
|
|||
where
|
||||
R: Copy + Hash + Eq,
|
||||
{
|
||||
pub(crate) fn all_indices(
|
||||
&self,
|
||||
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
|
||||
pub(crate) fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> {
|
||||
self.constraints.indices()
|
||||
}
|
||||
|
||||
|
@ -159,7 +156,7 @@ where
|
|||
pub(crate) fn indices(
|
||||
&self,
|
||||
member_region_vid: R,
|
||||
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
|
||||
) -> impl Iterator<Item = NllMemberConstraintIndex> {
|
||||
let mut next = self.first_constraints.get(&member_region_vid).cloned();
|
||||
std::iter::from_fn(move || -> Option<NllMemberConstraintIndex> {
|
||||
if let Some(current) = next {
|
||||
|
|
|
@ -175,7 +175,7 @@ impl LocalizedConstraintGraph {
|
|||
}
|
||||
|
||||
/// Returns the outgoing edges of a given node, not its transitive closure.
|
||||
fn outgoing_edges(&self, node: LocalizedNode) -> impl Iterator<Item = LocalizedNode> + use<'_> {
|
||||
fn outgoing_edges(&self, node: LocalizedNode) -> impl Iterator<Item = LocalizedNode> {
|
||||
// The outgoing edges are:
|
||||
// - the physical edges present at this node,
|
||||
// - the materialized logical edges that exist virtually at all points for this node's
|
||||
|
|
|
@ -576,9 +576,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
}
|
||||
|
||||
/// Returns an iterator over all the outlives constraints.
|
||||
pub(crate) fn outlives_constraints(
|
||||
&self,
|
||||
) -> impl Iterator<Item = OutlivesConstraint<'tcx>> + '_ {
|
||||
pub(crate) fn outlives_constraints(&self) -> impl Iterator<Item = OutlivesConstraint<'tcx>> {
|
||||
self.constraints.outlives().iter().copied()
|
||||
}
|
||||
|
||||
|
@ -615,10 +613,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
self.scc_values.region_value_str(scc)
|
||||
}
|
||||
|
||||
pub(crate) fn placeholders_contained_in<'a>(
|
||||
&'a self,
|
||||
pub(crate) fn placeholders_contained_in(
|
||||
&self,
|
||||
r: RegionVid,
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion> {
|
||||
let scc = self.constraint_sccs.scc(r);
|
||||
self.scc_values.placeholders_contained_in(scc)
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@ pub(crate) struct ReverseSccGraph {
|
|||
|
||||
impl ReverseSccGraph {
|
||||
/// Find all universal regions that are required to outlive the given SCC.
|
||||
pub(super) fn upper_bounds<'a>(
|
||||
&'a self,
|
||||
scc0: ConstraintSccIndex,
|
||||
) -> impl Iterator<Item = RegionVid> + 'a {
|
||||
pub(super) fn upper_bounds(&self, scc0: ConstraintSccIndex) -> impl Iterator<Item = RegionVid> {
|
||||
let mut duplicates = FxIndexSet::default();
|
||||
graph::depth_first_search(&self.graph, scc0)
|
||||
.flat_map(move |scc1| {
|
||||
|
|
|
@ -88,7 +88,7 @@ impl LivenessValues {
|
|||
}
|
||||
|
||||
/// Iterate through each region that has a value in this set.
|
||||
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + '_ {
|
||||
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> {
|
||||
self.points.as_ref().expect("use with_specific_points").rows()
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ impl LivenessValues {
|
|||
// We are passing query instability implications to the caller.
|
||||
#[rustc_lint_query_instability]
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
pub(crate) fn live_regions_unordered(&self) -> impl Iterator<Item = RegionVid> + '_ {
|
||||
pub(crate) fn live_regions_unordered(&self) -> impl Iterator<Item = RegionVid> {
|
||||
self.live_regions.as_ref().unwrap().iter().copied()
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ impl LivenessValues {
|
|||
}
|
||||
|
||||
/// Returns an iterator of all the points where `region` is live.
|
||||
fn live_points(&self, region: RegionVid) -> impl Iterator<Item = PointIndex> + '_ {
|
||||
fn live_points(&self, region: RegionVid) -> impl Iterator<Item = PointIndex> {
|
||||
let Some(points) = &self.points else {
|
||||
unreachable!(
|
||||
"Should be using LivenessValues::with_specific_points to ask whether live at a location"
|
||||
|
@ -340,7 +340,7 @@ impl<N: Idx> RegionValues<N> {
|
|||
}
|
||||
|
||||
/// Returns the locations contained within a given region `r`.
|
||||
pub(crate) fn locations_outlived_by<'a>(&'a self, r: N) -> impl Iterator<Item = Location> + 'a {
|
||||
pub(crate) fn locations_outlived_by(&self, r: N) -> impl Iterator<Item = Location> {
|
||||
self.points.row(r).into_iter().flat_map(move |set| {
|
||||
set.iter()
|
||||
.take_while(move |&p| self.location_map.point_in_range(p))
|
||||
|
@ -349,18 +349,15 @@ impl<N: Idx> RegionValues<N> {
|
|||
}
|
||||
|
||||
/// Returns just the universal regions that are contained in a given region's value.
|
||||
pub(crate) fn universal_regions_outlived_by<'a>(
|
||||
&'a self,
|
||||
r: N,
|
||||
) -> impl Iterator<Item = RegionVid> + 'a {
|
||||
pub(crate) fn universal_regions_outlived_by(&self, r: N) -> impl Iterator<Item = RegionVid> {
|
||||
self.free_regions.row(r).into_iter().flat_map(|set| set.iter())
|
||||
}
|
||||
|
||||
/// Returns all the elements contained in a given region's value.
|
||||
pub(crate) fn placeholders_contained_in<'a>(
|
||||
&'a self,
|
||||
pub(crate) fn placeholders_contained_in(
|
||||
&self,
|
||||
r: N,
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion> {
|
||||
self.placeholders
|
||||
.row(r)
|
||||
.into_iter()
|
||||
|
@ -369,10 +366,7 @@ impl<N: Idx> RegionValues<N> {
|
|||
}
|
||||
|
||||
/// Returns all the elements contained in a given region's value.
|
||||
pub(crate) fn elements_contained_in<'a>(
|
||||
&'a self,
|
||||
r: N,
|
||||
) -> impl Iterator<Item = RegionElement> + 'a {
|
||||
pub(crate) fn elements_contained_in(&self, r: N) -> impl Iterator<Item = RegionElement> {
|
||||
let points_iter = self.locations_outlived_by(r).map(RegionElement::Location);
|
||||
|
||||
let free_regions_iter =
|
||||
|
|
|
@ -172,7 +172,7 @@ impl UniversalRegionRelations<'_> {
|
|||
}
|
||||
|
||||
/// Returns the _non-transitive_ set of known `outlives` constraints between free regions.
|
||||
pub(crate) fn known_outlives(&self) -> impl Iterator<Item = (RegionVid, RegionVid)> + '_ {
|
||||
pub(crate) fn known_outlives(&self) -> impl Iterator<Item = (RegionVid, RegionVid)> {
|
||||
self.outlives.base_edges()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ rustc_index::newtype_index! {
|
|||
fn appearances_iter(
|
||||
first: Option<AppearanceIndex>,
|
||||
appearances: &Appearances,
|
||||
) -> impl Iterator<Item = AppearanceIndex> + '_ {
|
||||
) -> impl Iterator<Item = AppearanceIndex> {
|
||||
AppearancesIter { appearances, current: first }
|
||||
}
|
||||
|
||||
|
@ -107,17 +107,17 @@ impl LocalUseMap {
|
|||
local_use_map
|
||||
}
|
||||
|
||||
pub(crate) fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
|
||||
pub(crate) fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> {
|
||||
appearances_iter(self.first_def_at[local], &self.appearances)
|
||||
.map(move |aa| self.appearances[aa].point_index)
|
||||
}
|
||||
|
||||
pub(crate) fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
|
||||
pub(crate) fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> {
|
||||
appearances_iter(self.first_use_at[local], &self.appearances)
|
||||
.map(move |aa| self.appearances[aa].point_index)
|
||||
}
|
||||
|
||||
pub(crate) fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
|
||||
pub(crate) fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> {
|
||||
appearances_iter(self.first_drop_at[local], &self.appearances)
|
||||
.map(move |aa| self.appearances[aa].point_index)
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||
|
||||
/// Returns an iterator over all the RegionVids corresponding to
|
||||
/// universally quantified free regions.
|
||||
pub(crate) fn universal_regions_iter(&self) -> impl Iterator<Item = RegionVid> + use<> {
|
||||
pub(crate) fn universal_regions_iter(&self) -> impl Iterator<Item = RegionVid> + 'static {
|
||||
(FIRST_GLOBAL_INDEX..self.num_universals).map(RegionVid::from_usize)
|
||||
}
|
||||
|
||||
|
@ -332,9 +332,9 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||
}
|
||||
|
||||
/// Gets an iterator over all the early-bound regions that have names.
|
||||
pub(crate) fn named_universal_regions_iter<'s>(
|
||||
&'s self,
|
||||
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's {
|
||||
pub(crate) fn named_universal_regions_iter(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> {
|
||||
self.indices.indices.iter().map(|(&r, &v)| (r, v))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue