Skip to content

Commit 7f14d2e

Browse files
authored
Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross
Greatly simplify lifetime captures in edition 2024 Remove most of the `+ Captures` and `+ '_` from the compiler, since they are now unnecessary with the new edition 2021 lifetime capture rules. Use some `+ 'tcx` and `+ 'static` rather than being overly verbose with precise capturing syntax.
2 parents 2ff53a2 + 12e3911 commit 7f14d2e

File tree

84 files changed

+223
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+223
-294
lines changed

compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ impl<FieldIdx: Idx> FieldsShape<FieldIdx> {
13491349

13501350
/// Gets source indices of the fields by increasing offsets.
13511351
#[inline]
1352-
pub fn index_by_increasing_offset(&self) -> impl ExactSizeIterator<Item = usize> + '_ {
1352+
pub fn index_by_increasing_offset(&self) -> impl ExactSizeIterator<Item = usize> {
13531353
let mut inverse_small = [0u8; 64];
13541354
let mut inverse_big = IndexVec::new();
13551355
let use_small = self.count() <= inverse_small.len();

compiler/rustc_ast_lowering/src/lib.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use std::sync::Arc;
4545

4646
use rustc_ast::node_id::NodeMap;
4747
use rustc_ast::{self as ast, *};
48-
use rustc_data_structures::captures::Captures;
4948
use rustc_data_structures::fingerprint::Fingerprint;
5049
use rustc_data_structures::sorted_map::SortedMap;
5150
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -1821,11 +1820,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18211820
self.new_named_lifetime_with_res(new_id, ident, res)
18221821
}
18231822

1824-
fn lower_generic_params_mut<'s>(
1825-
&'s mut self,
1826-
params: &'s [GenericParam],
1823+
fn lower_generic_params_mut(
1824+
&mut self,
1825+
params: &[GenericParam],
18271826
source: hir::GenericParamSource,
1828-
) -> impl Iterator<Item = hir::GenericParam<'hir>> + Captures<'a> + Captures<'s> {
1827+
) -> impl Iterator<Item = hir::GenericParam<'hir>> {
18291828
params.iter().map(move |param| self.lower_generic_param(param, source))
18301829
}
18311830

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

1989-
fn lower_param_bounds_mut<'s>(
1990-
&'s mut self,
1991-
bounds: &'s [GenericBound],
1988+
fn lower_param_bounds_mut(
1989+
&mut self,
1990+
bounds: &[GenericBound],
19921991
itctx: ImplTraitContext,
1993-
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
1992+
) -> impl Iterator<Item = hir::GenericBound<'hir>> {
19941993
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
19951994
}
19961995

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ use rustc_span::{Symbol, sym};
44

55
use crate::session_diagnostics;
66

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

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

21-
fn allow_unstable<'a>(
22-
sess: &'a Session,
23-
attrs: &'a [impl AttributeExt],
21+
fn allow_unstable(
22+
sess: &Session,
23+
attrs: &[impl AttributeExt],
2424
symbol: Symbol,
25-
) -> impl Iterator<Item = Symbol> + 'a {
25+
) -> impl Iterator<Item = Symbol> {
2626
let attrs = filter_by_name(attrs, symbol);
2727
let list = attrs
2828
.filter_map(move |attr| {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::ops::ControlFlow;
88

99
use either::Either;
1010
use hir::{ClosureKind, Path};
11-
use rustc_data_structures::captures::Captures;
1211
use rustc_data_structures::fx::FxIndexSet;
1312
use rustc_errors::codes::*;
1413
use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err};
@@ -3530,10 +3529,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
35303529
location: Location,
35313530
mpi: MovePathIndex,
35323531
) -> (Vec<MoveSite>, Vec<Location>) {
3533-
fn predecessor_locations<'a, 'tcx>(
3534-
body: &'a mir::Body<'tcx>,
3532+
fn predecessor_locations<'tcx>(
3533+
body: &mir::Body<'tcx>,
35353534
location: Location,
3536-
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
3535+
) -> impl Iterator<Item = Location> {
35373536
if location.statement_index == 0 {
35383537
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
35393538
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))

compiler/rustc_borrowck/src/member_constraints.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::hash::Hash;
22
use std::ops::Index;
33

4-
use rustc_data_structures::captures::Captures;
54
use rustc_data_structures::fx::FxIndexMap;
65
use rustc_index::{IndexSlice, IndexVec};
76
use rustc_middle::ty::{self, Ty};
@@ -147,9 +146,7 @@ impl<'tcx, R> MemberConstraintSet<'tcx, R>
147146
where
148147
R: Copy + Hash + Eq,
149148
{
150-
pub(crate) fn all_indices(
151-
&self,
152-
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
149+
pub(crate) fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> {
153150
self.constraints.indices()
154151
}
155152

@@ -159,7 +156,7 @@ where
159156
pub(crate) fn indices(
160157
&self,
161158
member_region_vid: R,
162-
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
159+
) -> impl Iterator<Item = NllMemberConstraintIndex> {
163160
let mut next = self.first_constraints.get(&member_region_vid).cloned();
164161
std::iter::from_fn(move || -> Option<NllMemberConstraintIndex> {
165162
if let Some(current) = next {

compiler/rustc_borrowck/src/polonius/loan_liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl LocalizedConstraintGraph {
175175
}
176176

177177
/// Returns the outgoing edges of a given node, not its transitive closure.
178-
fn outgoing_edges(&self, node: LocalizedNode) -> impl Iterator<Item = LocalizedNode> + use<'_> {
178+
fn outgoing_edges(&self, node: LocalizedNode) -> impl Iterator<Item = LocalizedNode> {
179179
// The outgoing edges are:
180180
// - the physical edges present at this node,
181181
// - the materialized logical edges that exist virtually at all points for this node's

compiler/rustc_borrowck/src/region_infer/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
576576
}
577577

578578
/// Returns an iterator over all the outlives constraints.
579-
pub(crate) fn outlives_constraints(
580-
&self,
581-
) -> impl Iterator<Item = OutlivesConstraint<'tcx>> + '_ {
579+
pub(crate) fn outlives_constraints(&self) -> impl Iterator<Item = OutlivesConstraint<'tcx>> {
582580
self.constraints.outlives().iter().copied()
583581
}
584582

@@ -615,10 +613,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
615613
self.scc_values.region_value_str(scc)
616614
}
617615

618-
pub(crate) fn placeholders_contained_in<'a>(
619-
&'a self,
616+
pub(crate) fn placeholders_contained_in(
617+
&self,
620618
r: RegionVid,
621-
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
619+
) -> impl Iterator<Item = ty::PlaceholderRegion> {
622620
let scc = self.constraint_sccs.scc(r);
623621
self.scc_values.placeholders_contained_in(scc)
624622
}

compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ pub(crate) struct ReverseSccGraph {
2020

2121
impl ReverseSccGraph {
2222
/// Find all universal regions that are required to outlive the given SCC.
23-
pub(super) fn upper_bounds<'a>(
24-
&'a self,
25-
scc0: ConstraintSccIndex,
26-
) -> impl Iterator<Item = RegionVid> + 'a {
23+
pub(super) fn upper_bounds(&self, scc0: ConstraintSccIndex) -> impl Iterator<Item = RegionVid> {
2724
let mut duplicates = FxIndexSet::default();
2825
graph::depth_first_search(&self.graph, scc0)
2926
.flat_map(move |scc1| {

compiler/rustc_borrowck/src/region_infer/values.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ impl LivenessValues {
8888
}
8989

9090
/// Iterate through each region that has a value in this set.
91-
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + '_ {
91+
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> {
9292
self.points.as_ref().expect("use with_specific_points").rows()
9393
}
9494

9595
/// Iterate through each region that has a value in this set.
9696
// We are passing query instability implications to the caller.
9797
#[rustc_lint_query_instability]
9898
#[allow(rustc::potential_query_instability)]
99-
pub(crate) fn live_regions_unordered(&self) -> impl Iterator<Item = RegionVid> + '_ {
99+
pub(crate) fn live_regions_unordered(&self) -> impl Iterator<Item = RegionVid> {
100100
self.live_regions.as_ref().unwrap().iter().copied()
101101
}
102102

@@ -143,7 +143,7 @@ impl LivenessValues {
143143
}
144144

145145
/// Returns an iterator of all the points where `region` is live.
146-
fn live_points(&self, region: RegionVid) -> impl Iterator<Item = PointIndex> + '_ {
146+
fn live_points(&self, region: RegionVid) -> impl Iterator<Item = PointIndex> {
147147
let Some(points) = &self.points else {
148148
unreachable!(
149149
"Should be using LivenessValues::with_specific_points to ask whether live at a location"
@@ -340,7 +340,7 @@ impl<N: Idx> RegionValues<N> {
340340
}
341341

342342
/// Returns the locations contained within a given region `r`.
343-
pub(crate) fn locations_outlived_by<'a>(&'a self, r: N) -> impl Iterator<Item = Location> + 'a {
343+
pub(crate) fn locations_outlived_by(&self, r: N) -> impl Iterator<Item = Location> {
344344
self.points.row(r).into_iter().flat_map(move |set| {
345345
set.iter()
346346
.take_while(move |&p| self.location_map.point_in_range(p))
@@ -349,18 +349,15 @@ impl<N: Idx> RegionValues<N> {
349349
}
350350

351351
/// Returns just the universal regions that are contained in a given region's value.
352-
pub(crate) fn universal_regions_outlived_by<'a>(
353-
&'a self,
354-
r: N,
355-
) -> impl Iterator<Item = RegionVid> + 'a {
352+
pub(crate) fn universal_regions_outlived_by(&self, r: N) -> impl Iterator<Item = RegionVid> {
356353
self.free_regions.row(r).into_iter().flat_map(|set| set.iter())
357354
}
358355

359356
/// Returns all the elements contained in a given region's value.
360-
pub(crate) fn placeholders_contained_in<'a>(
361-
&'a self,
357+
pub(crate) fn placeholders_contained_in(
358+
&self,
362359
r: N,
363-
) -> impl Iterator<Item = ty::PlaceholderRegion> + 'a {
360+
) -> impl Iterator<Item = ty::PlaceholderRegion> {
364361
self.placeholders
365362
.row(r)
366363
.into_iter()
@@ -369,10 +366,7 @@ impl<N: Idx> RegionValues<N> {
369366
}
370367

371368
/// Returns all the elements contained in a given region's value.
372-
pub(crate) fn elements_contained_in<'a>(
373-
&'a self,
374-
r: N,
375-
) -> impl Iterator<Item = RegionElement> + 'a {
369+
pub(crate) fn elements_contained_in(&self, r: N) -> impl Iterator<Item = RegionElement> {
376370
let points_iter = self.locations_outlived_by(r).map(RegionElement::Location);
377371

378372
let free_regions_iter =

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl UniversalRegionRelations<'_> {
172172
}
173173

174174
/// Returns the _non-transitive_ set of known `outlives` constraints between free regions.
175-
pub(crate) fn known_outlives(&self) -> impl Iterator<Item = (RegionVid, RegionVid)> + '_ {
175+
pub(crate) fn known_outlives(&self) -> impl Iterator<Item = (RegionVid, RegionVid)> {
176176
self.outlives.base_edges()
177177
}
178178
}

compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ rustc_index::newtype_index! {
5454
fn appearances_iter(
5555
first: Option<AppearanceIndex>,
5656
appearances: &Appearances,
57-
) -> impl Iterator<Item = AppearanceIndex> + '_ {
57+
) -> impl Iterator<Item = AppearanceIndex> {
5858
AppearancesIter { appearances, current: first }
5959
}
6060

@@ -107,17 +107,17 @@ impl LocalUseMap {
107107
local_use_map
108108
}
109109

110-
pub(crate) fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
110+
pub(crate) fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> {
111111
appearances_iter(self.first_def_at[local], &self.appearances)
112112
.map(move |aa| self.appearances[aa].point_index)
113113
}
114114

115-
pub(crate) fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
115+
pub(crate) fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> {
116116
appearances_iter(self.first_use_at[local], &self.appearances)
117117
.map(move |aa| self.appearances[aa].point_index)
118118
}
119119

120-
pub(crate) fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
120+
pub(crate) fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> {
121121
appearances_iter(self.first_drop_at[local], &self.appearances)
122122
.map(move |aa| self.appearances[aa].point_index)
123123
}

compiler/rustc_borrowck/src/universal_regions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'tcx> UniversalRegions<'tcx> {
318318

319319
/// Returns an iterator over all the RegionVids corresponding to
320320
/// universally quantified free regions.
321-
pub(crate) fn universal_regions_iter(&self) -> impl Iterator<Item = RegionVid> + use<> {
321+
pub(crate) fn universal_regions_iter(&self) -> impl Iterator<Item = RegionVid> + 'static {
322322
(FIRST_GLOBAL_INDEX..self.num_universals).map(RegionVid::from_usize)
323323
}
324324

@@ -342,9 +342,9 @@ impl<'tcx> UniversalRegions<'tcx> {
342342
}
343343

344344
/// Gets an iterator over all the early-bound regions that have names.
345-
pub(crate) fn named_universal_regions_iter<'s>(
346-
&'s self,
347-
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> + 's {
345+
pub(crate) fn named_universal_regions_iter(
346+
&self,
347+
) -> impl Iterator<Item = (ty::Region<'tcx>, ty::RegionVid)> {
348348
self.indices.indices.iter().map(|(&r, &v)| (r, v))
349349
}
350350

compiler/rustc_const_eval/src/interpret/intern.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl HasStaticRootDefId for const_eval::CompileTimeMachine<'_> {
6161
/// already mutable (as a sanity check).
6262
///
6363
/// Returns an iterator over all relocations referred to by this allocation.
64-
fn intern_shallow<'rt, 'tcx, T, M: CompileTimeMachine<'tcx, T>>(
65-
ecx: &'rt mut InterpCx<'tcx, M>,
64+
fn intern_shallow<'tcx, T, M: CompileTimeMachine<'tcx, T>>(
65+
ecx: &mut InterpCx<'tcx, M>,
6666
alloc_id: AllocId,
6767
mutability: Mutability,
6868
) -> Result<impl Iterator<Item = CtfeProvenance> + 'tcx, ()> {

compiler/rustc_data_structures/src/graph/implementation/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ impl<N: Debug, E: Debug> Graph<N, E> {
193193
AdjacentEdges { graph: self, direction, next: first_edge }
194194
}
195195

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

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

@@ -255,11 +255,11 @@ pub struct AdjacentEdges<'g, N, E> {
255255
}
256256

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

262-
fn sources(self) -> impl Iterator<Item = NodeIndex> + 'g {
262+
fn sources(self) -> impl Iterator<Item = NodeIndex> {
263263
self.map(|(_, edge)| edge.source)
264264
}
265265
}

compiler/rustc_data_structures/src/graph/scc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<N: Idx, S: Idx + Ord, A: Annotation> Sccs<N, S, A> {
133133
/// meaning that if `S1 -> S2`, we will visit `S2` first and `S1` after.
134134
/// This is convenient when the edges represent dependencies: when you visit
135135
/// `S1`, the value for `S2` will already have been computed.
136-
pub fn all_sccs(&self) -> impl Iterator<Item = S> + use<N, S, A> {
136+
pub fn all_sccs(&self) -> impl Iterator<Item = S> + 'static {
137137
(0..self.scc_data.len()).map(S::new)
138138
}
139139

compiler/rustc_data_structures/src/sorted_map/index_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
8484
/// If there are multiple items that are equivalent to `key`, they will be yielded in
8585
/// insertion order.
8686
#[inline]
87-
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> + '_ {
87+
pub fn get_by_key(&self, key: K) -> impl Iterator<Item = &V> {
8888
self.get_by_key_enumerated(key).map(|(_, v)| v)
8989
}
9090

@@ -94,7 +94,7 @@ impl<I: Idx, K: Ord, V> SortedIndexMultiMap<I, K, V> {
9494
/// If there are multiple items that are equivalent to `key`, they will be yielded in
9595
/// insertion order.
9696
#[inline]
97-
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> + '_ {
97+
pub fn get_by_key_enumerated(&self, key: K) -> impl Iterator<Item = (I, &V)> {
9898
let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
9999
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {
100100
let (k, v) = &self.items[i];

compiler/rustc_data_structures/src/sso/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<K, V> SsoHashMap<K, V> {
165165

166166
/// Clears the map, returning all key-value pairs as an iterator. Keeps the
167167
/// allocated memory for reuse.
168-
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_ {
168+
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> {
169169
match self {
170170
SsoHashMap::Array(array) => Either::Left(array.drain(..)),
171171
SsoHashMap::Map(map) => Either::Right(map.drain()),

compiler/rustc_data_structures/src/sso/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<T> SsoHashSet<T> {
8080

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

0 commit comments

Comments
 (0)