Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greatly simplify lifetime captures in edition 2024 #137334

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ impl<FieldIdx: Idx> FieldsShape<FieldIdx> {

/// Gets source indices of the fields by increasing offsets.
#[inline]
pub fn index_by_increasing_offset(&self) -> impl ExactSizeIterator<Item = usize> + '_ {
pub fn index_by_increasing_offset(&self) -> impl ExactSizeIterator<Item = usize> {
let mut inverse_small = [0u8; 64];
let mut inverse_big = IndexVec::new();
let use_small = self.count() <= inverse_small.len();
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use std::sync::Arc;

use rustc_ast::node_id::NodeMap;
use rustc_ast::{self as ast, *};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -1821,11 +1820,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.new_named_lifetime_with_res(new_id, ident, res)
}

fn lower_generic_params_mut<'s>(
&'s mut self,
params: &'s [GenericParam],
fn lower_generic_params_mut(
&mut self,
params: &[GenericParam],
source: hir::GenericParamSource,
) -> impl Iterator<Item = hir::GenericParam<'hir>> + Captures<'a> + Captures<'s> {
) -> impl Iterator<Item = hir::GenericParam<'hir>> {
params.iter().map(move |param| self.lower_generic_param(param, source))
}

Expand Down Expand Up @@ -1986,11 +1985,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, itctx))
}

fn lower_param_bounds_mut<'s>(
&'s mut self,
bounds: &'s [GenericBound],
fn lower_param_bounds_mut(
&mut self,
bounds: &[GenericBound],
itctx: ImplTraitContext,
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
) -> impl Iterator<Item = hir::GenericBound<'hir>> {
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
}

Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ use rustc_span::{Symbol, sym};

use crate::session_diagnostics;

pub fn allow_internal_unstable<'a>(
sess: &'a Session,
attrs: &'a [impl AttributeExt],
) -> impl Iterator<Item = Symbol> + 'a {
pub fn allow_internal_unstable(
sess: &Session,
attrs: &[impl AttributeExt],
) -> impl Iterator<Item = Symbol> {
allow_unstable(sess, attrs, sym::allow_internal_unstable)
}

pub fn rustc_allow_const_fn_unstable<'a>(
sess: &'a Session,
attrs: &'a [impl AttributeExt],
) -> impl Iterator<Item = Symbol> + 'a {
pub fn rustc_allow_const_fn_unstable(
sess: &Session,
attrs: &[impl AttributeExt],
) -> impl Iterator<Item = Symbol> {
allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)
}

fn allow_unstable<'a>(
sess: &'a Session,
attrs: &'a [impl AttributeExt],
fn allow_unstable(
sess: &Session,
attrs: &[impl AttributeExt],
symbol: Symbol,
) -> impl Iterator<Item = Symbol> + 'a {
) -> impl Iterator<Item = Symbol> {
let attrs = filter_by_name(attrs, symbol);
let list = attrs
.filter_map(move |attr| {
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)))
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_borrowck/src/member_constraints.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
}

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/polonius/loan_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
24 changes: 9 additions & 15 deletions compiler/rustc_borrowck/src/region_infer/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ 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()
}

/// Iterate through each region that has a value in this set.
// 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()
}

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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()
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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))
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl HasStaticRootDefId for const_eval::CompileTimeMachine<'_> {
/// already mutable (as a sanity check).
///
/// Returns an iterator over all relocations referred to by this allocation.
fn intern_shallow<'rt, 'tcx, T, M: CompileTimeMachine<'tcx, T>>(
ecx: &'rt mut InterpCx<'tcx, M>,
fn intern_shallow<'tcx, T, M: CompileTimeMachine<'tcx, T>>(
ecx: &mut InterpCx<'tcx, M>,
alloc_id: AllocId,
mutability: Mutability,
) -> Result<impl Iterator<Item = CtfeProvenance> + 'tcx, ()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ impl<N: Debug, E: Debug> Graph<N, E> {
AdjacentEdges { graph: self, direction, next: first_edge }
}

pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> {
self.outgoing_edges(source).targets()
}

pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> {
self.incoming_edges(target).sources()
}

Expand Down Expand Up @@ -255,11 +255,11 @@ pub struct AdjacentEdges<'g, N, E> {
}

impl<'g, N: Debug, E: Debug> AdjacentEdges<'g, N, E> {
fn targets(self) -> impl Iterator<Item = NodeIndex> + 'g {
fn targets(self) -> impl Iterator<Item = NodeIndex> {
self.map(|(_, edge)| edge.target)
}

fn sources(self) -> impl Iterator<Item = NodeIndex> + 'g {
fn sources(self) -> impl Iterator<Item = NodeIndex> {
self.map(|(_, edge)| edge.source)
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<N: Idx, S: Idx + Ord, A: Annotation> Sccs<N, S, A> {
/// meaning that if `S1 -> S2`, we will visit `S2` first and `S1` after.
/// This is convenient when the edges represent dependencies: when you visit
/// `S1`, the value for `S2` will already have been computed.
pub fn all_sccs(&self) -> impl Iterator<Item = S> + use<N, S, A> {
pub fn all_sccs(&self) -> impl Iterator<Item = S> + 'static {
(0..self.scc_data.len()).map(S::new)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/sorted_map/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
/// If there are multiple items that are equivalent to `key`, they will be yielded in
/// insertion order.
#[inline]
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> + '_ {
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> {
self.get_by_key_enumerated(key).map(|(_, v)| v)
}

Expand All @@ -94,7 +94,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
/// If there are multiple items that are equivalent to `key`, they will be yielded in
/// insertion order.
#[inline]
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> + '_ {
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> {
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
let (k, v) = &self.items[i];
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sso/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<K, V> SsoHashMap<K, V> {

/// Clears the map, returning all key-value pairs as an iterator. Keeps the
/// allocated memory for reuse.
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_ {
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> {
match self {
SsoHashMap::Array(array) => Either::Left(array.drain(..)),
SsoHashMap::Map(map) => Either::Right(map.drain()),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sso/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<T> SsoHashSet<T> {

/// Clears the set, returning all elements in an iterator.
#[inline]
pub fn drain(&mut self) -> impl Iterator<Item = T> + '_ {
pub fn drain(&mut self) -> impl Iterator<Item = T> {
self.map.drain().map(entry_to_key)
}
}
Expand Down
Loading
Loading