1
Fork 0

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.
This commit is contained in:
Jacob Pratt 2025-02-23 02:44:18 -05:00 committed by GitHub
commit 7f14d2eba4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
84 changed files with 223 additions and 294 deletions

View file

@ -174,15 +174,12 @@ impl<'tcx> TyCtxt<'tcx> {
}
#[inline]
pub fn hir_free_items(self) -> impl Iterator<Item = ItemId> + 'tcx {
pub fn hir_free_items(self) -> impl Iterator<Item = ItemId> {
self.hir_crate_items(()).free_items.iter().copied()
}
#[inline]
pub fn hir_module_free_items(
self,
module: LocalModDefId,
) -> impl Iterator<Item = ItemId> + 'tcx {
pub fn hir_module_free_items(self, module: LocalModDefId) -> impl Iterator<Item = ItemId> {
self.hir_module_items(module).free_items()
}
@ -283,7 +280,7 @@ impl<'tcx> TyCtxt<'tcx> {
})
}
pub fn hir_body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'tcx {
pub fn hir_body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> {
self.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
PatKind::Binding(_, _, ident, _) => ident,
_ => Ident::empty(),
@ -338,7 +335,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
#[inline]
pub fn hir_body_owners(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
pub fn hir_body_owners(self) -> impl Iterator<Item = LocalDefId> {
self.hir_crate_items(()).body_owners.iter().copied()
}
@ -503,7 +500,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
#[inline]
pub fn hir_parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'tcx {
pub fn hir_parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> {
ParentHirIterator::new(self, current_id)
}

View file

@ -40,25 +40,25 @@ impl ModuleItems {
/// include foreign items. If you want to e.g. get all functions, use `definitions()` below.
///
/// However, this does include the `impl` blocks themselves.
pub fn free_items(&self) -> impl Iterator<Item = ItemId> + '_ {
pub fn free_items(&self) -> impl Iterator<Item = ItemId> {
self.free_items.iter().copied()
}
pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> + '_ {
pub fn trait_items(&self) -> impl Iterator<Item = TraitItemId> {
self.trait_items.iter().copied()
}
/// Returns all items that are associated with some `impl` block (both inherent and trait impl
/// blocks).
pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> + '_ {
pub fn impl_items(&self) -> impl Iterator<Item = ImplItemId> {
self.impl_items.iter().copied()
}
pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> + '_ {
pub fn foreign_items(&self) -> impl Iterator<Item = ForeignItemId> {
self.foreign_items.iter().copied()
}
pub fn owners(&self) -> impl Iterator<Item = OwnerId> + '_ {
pub fn owners(&self) -> impl Iterator<Item = OwnerId> {
self.free_items
.iter()
.map(|id| id.owner_id)
@ -67,15 +67,15 @@ impl ModuleItems {
.chain(self.foreign_items.iter().map(|id| id.owner_id))
}
pub fn opaques(&self) -> impl Iterator<Item = LocalDefId> + '_ {
pub fn opaques(&self) -> impl Iterator<Item = LocalDefId> {
self.opaques.iter().copied()
}
pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> + '_ {
pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
self.nested_bodies.iter().copied()
}
pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> + '_ {
pub fn definitions(&self) -> impl Iterator<Item = LocalDefId> {
self.owners().map(|id| id.def_id)
}

View file

@ -97,7 +97,7 @@ impl<'tcx> Place<'tcx> {
/// The types are in the reverse order that they are applied. So if
/// `x: &*const u32` and the `Place` is `**x`, then the types returned are
///`*const u32` then `&*const u32`.
pub fn deref_tys(&self) -> impl Iterator<Item = Ty<'tcx>> + '_ {
pub fn deref_tys(&self) -> impl Iterator<Item = Ty<'tcx>> {
self.projections.iter().enumerate().rev().filter_map(move |(index, proj)| {
if ProjectionKind::Deref == proj.kind {
Some(self.ty_before_projection(index))

View file

@ -121,7 +121,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
}
/// Yields all the provenances stored in this map.
pub fn provenances(&self) -> impl Iterator<Item = Prov> + '_ {
pub fn provenances(&self) -> impl Iterator<Item = Prov> {
let bytes = self.bytes.iter().flat_map(|b| b.values());
self.ptrs.values().chain(bytes).copied()
}

View file

@ -12,7 +12,6 @@ use either::Either;
use polonius_engine::Atom;
use rustc_abi::{FieldIdx, VariantIdx};
pub use rustc_ast::Mutability;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::dominators::Dominators;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
@ -472,7 +471,7 @@ impl<'tcx> Body<'tcx> {
/// Returns an iterator over all user-declared mutable locals.
#[inline]
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
pub fn mut_vars_iter(&self) -> impl Iterator<Item = Local> {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
@ -482,9 +481,7 @@ impl<'tcx> Body<'tcx> {
/// Returns an iterator over all user-declared mutable arguments and locals.
#[inline]
pub fn mut_vars_and_args_iter<'a>(
&'a self,
) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
pub fn mut_vars_and_args_iter(&self) -> impl Iterator<Item = Local> {
(1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
@ -514,7 +511,7 @@ impl<'tcx> Body<'tcx> {
}
#[inline]
pub fn drain_vars_and_temps<'a>(&'a mut self) -> impl Iterator<Item = LocalDecl<'tcx>> + 'a {
pub fn drain_vars_and_temps(&mut self) -> impl Iterator<Item = LocalDecl<'tcx>> {
self.local_decls.drain(self.arg_count + 1..)
}

View file

@ -1523,7 +1523,7 @@ pub fn write_allocations<'tcx>(
) -> io::Result<()> {
fn alloc_ids_from_alloc(
alloc: ConstAllocation<'_>,
) -> impl DoubleEndedIterator<Item = AllocId> + '_ {
) -> impl DoubleEndedIterator<Item = AllocId> {
alloc.inner().provenance().ptrs().values().map(|p| p.alloc_id())
}

View file

@ -4,7 +4,6 @@ use std::ops::Range;
use std::str;
use rustc_abi::{FIRST_VARIANT, ReprOptions, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::intern::Interned;
@ -540,7 +539,7 @@ impl<'tcx> AdtDef<'tcx> {
pub fn discriminants(
self,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> {
assert!(self.is_enum());
let repr_type = self.repr().discr_type();
let initial = repr_type.initial_discriminant(tcx);

View file

@ -1,6 +1,5 @@
use std::fmt::Write;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir;
use rustc_hir::HirId;
@ -415,7 +414,7 @@ pub fn analyze_coroutine_closure_captures<'a, 'tcx: 'a, T>(
parent_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
child_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
mut for_each: impl FnMut((usize, &'a CapturedPlace<'tcx>), (usize, &'a CapturedPlace<'tcx>)) -> T,
) -> impl Iterator<Item = T> + Captures<'a> + Captures<'tcx> {
) -> impl Iterator<Item = T> {
std::iter::from_coroutine(
#[coroutine]
move || {

View file

@ -1943,7 +1943,7 @@ impl<'tcx> TyCtxt<'tcx> {
Ok(TyCtxtFeed { key: num, tcx: self })
}
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> {
// Create a dependency to the red node to be sure we re-execute this when the amount of
// definitions change.
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
@ -2175,14 +2175,14 @@ impl<'tcx> TyCtxt<'tcx> {
}
/// All traits in the crate graph, including those not visible to the user.
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
pub fn all_traits(self) -> impl Iterator<Item = DefId> {
iter::once(LOCAL_CRATE)
.chain(self.crates(()).iter().copied())
.flat_map(move |cnum| self.traits(cnum).iter().copied())
}
/// All traits that are visible within the crate graph (i.e. excluding private dependencies).
pub fn visible_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
pub fn visible_traits(self) -> impl Iterator<Item = DefId> {
let visible_crates =
self.crates(()).iter().copied().filter(move |cnum| self.is_user_visible_dep(*cnum));
@ -2367,7 +2367,7 @@ macro_rules! sty_debug_print {
}
impl<'tcx> TyCtxt<'tcx> {
pub fn debug_stats(self) -> impl fmt::Debug + 'tcx {
pub fn debug_stats(self) -> impl fmt::Debug {
fmt::from_fn(move |fmt| {
sty_debug_print!(
fmt,

View file

@ -479,25 +479,23 @@ impl<'tcx> GenericArgs<'tcx> {
}
#[inline]
pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx {
pub fn types(&self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> {
self.iter().filter_map(|k| k.as_type())
}
#[inline]
pub fn regions(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> + 'tcx {
pub fn regions(&self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> {
self.iter().filter_map(|k| k.as_region())
}
#[inline]
pub fn consts(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Const<'tcx>> + 'tcx {
pub fn consts(&self) -> impl DoubleEndedIterator<Item = ty::Const<'tcx>> {
self.iter().filter_map(|k| k.as_const())
}
/// Returns generic arguments that are not lifetimes.
#[inline]
pub fn non_erasable_generics(
&'tcx self,
) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> + 'tcx {
pub fn non_erasable_generics(&self) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> {
self.iter().filter_map(|k| match k.unpack() {
ty::GenericArgKind::Lifetime(_) => None,
generic => Some(generic),

View file

@ -1798,14 +1798,11 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
pub fn get_attrs_by_path<'attr>(
pub fn get_attrs_by_path(
self,
did: DefId,
attr: &'attr [Symbol],
) -> impl Iterator<Item = &'tcx hir::Attribute> + 'attr
where
'tcx: 'attr,
{
attr: &[Symbol],
) -> impl Iterator<Item = &'tcx hir::Attribute> {
let filter_fn = move |a: &&hir::Attribute| a.path_matches(attr);
if let Some(did) = did.as_local() {
self.hir().attrs(self.local_def_id_to_hir_id(did)).iter().filter(filter_fn)

View file

@ -1,6 +1,5 @@
use std::cmp::Ordering;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned;
use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, extension};
@ -336,9 +335,9 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
}
#[inline]
pub fn projection_bounds<'a>(
&'a self,
) -> impl Iterator<Item = ty::Binder<'tcx, ExistentialProjection<'tcx>>> + 'a {
pub fn projection_bounds(
&self,
) -> impl Iterator<Item = ty::Binder<'tcx, ExistentialProjection<'tcx>>> {
self.iter().filter_map(|predicate| {
predicate
.map_bound(|pred| match pred {
@ -350,16 +349,14 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
}
#[inline]
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'a {
pub fn auto_traits(&self) -> impl Iterator<Item = DefId> {
self.iter().filter_map(|predicate| match predicate.skip_binder() {
ExistentialPredicate::AutoTrait(did) => Some(did),
_ => None,
})
}
pub fn without_auto_traits(
&self,
) -> impl Iterator<Item = ty::PolyExistentialPredicate<'tcx>> + '_ {
pub fn without_auto_traits(&self) -> impl Iterator<Item = ty::PolyExistentialPredicate<'tcx>> {
self.iter().filter(|predicate| {
!matches!(predicate.as_ref().skip_binder(), ExistentialPredicate::AutoTrait(_))
})

View file

@ -9,7 +9,6 @@ use std::ops::{ControlFlow, Range};
use hir::def::{CtorKind, DefKind};
use rustc_abi::{ExternAbi, FIRST_VARIANT, FieldIdx, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_errors::{ErrorGuaranteed, MultiSpan};
use rustc_hir as hir;
use rustc_hir::LangItem;
@ -105,7 +104,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> {
self.variant_range(def_id, tcx).map(move |index| {
(index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) })
})
@ -139,7 +138,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>>> {
let layout = tcx.coroutine_layout(def_id, self.kind_ty()).unwrap();
layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| {

View file

@ -188,7 +188,7 @@ impl<'tcx> TyCtxt<'tcx> {
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
) -> impl Iterator<Item = DefId> + 'tcx {
) -> impl Iterator<Item = DefId> {
let impls = self.trait_impls_of(trait_def_id);
if let Some(simp) =
fast_reject::simplify_type(self, self_ty, TreatParams::InstantiateWithInfer)
@ -204,7 +204,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns an iterator containing all impls for `trait_def_id`.
///
/// `trait_def_id` MUST BE the `DefId` of a trait.
pub fn all_impls(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
pub fn all_impls(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> {
let TraitImpls { blanket_impls, non_blanket_impls } = self.trait_impls_of(trait_def_id);
blanket_impls.iter().chain(non_blanket_impls.iter().flat_map(|(_, v)| v)).cloned()

View file

@ -575,7 +575,7 @@ impl<'a, V> LocalTableInContext<'a, V> {
}
pub fn items(
&'a self,
&self,
) -> UnordItems<(hir::ItemLocalId, &'a V), impl Iterator<Item = (hir::ItemLocalId, &'a V)>>
{
self.data.items().map(|(id, value)| (*id, value))