Auto merge of #137466 - jhpratt:rollup-spyi02y, r=jhpratt

Rollup of 9 pull requests

Successful merges:

 - #135354 ([Debuginfo] Add MSVC Synthetic and Summary providers to LLDB)
 - #136826 (Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in Unix)
 - #137194 (More const {} init in thread_local)
 - #137334 (Greatly simplify lifetime captures in edition 2024)
 - #137382 (bootstrap: add doc for vendor build step)
 - #137423 (Improve a bit HIR pretty printer)
 - #137435 (Fix "missing match arm body" suggestion involving `!`)
 - #137448 (Fix bugs due to unhandled `ControlFlow` in compiler)
 - #137458 (Fix missing self subst when rendering `impl Fn*<T>` with no output type)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-02-23 08:06:25 +00:00
commit 1805b33483
117 changed files with 1151 additions and 420 deletions

View File

@ -1349,7 +1349,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();

View File

@ -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};
@ -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))
}
@ -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))
}

View File

@ -804,7 +804,14 @@ pub(crate) struct NegativeBoundWithParentheticalNotation {
pub(crate) struct MatchArmWithNoBody {
#[primary_span]
pub span: Span,
#[suggestion(code = " => todo!(),", applicability = "has-placeholders")]
// We include the braces around `todo!()` so that a comma is optional, and we don't have to have
// any logic looking at the arm being replaced if there was a comma already or not for the
// resulting code to be correct.
#[suggestion(
code = " => {{ todo!() }}",
applicability = "has-placeholders",
style = "verbose"
)]
pub suggestion: Span,
}

View File

@ -424,20 +424,23 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.ann_post(ident)
}
fn strsep<T, F>(
fn strsep<'x, T: 'x, F, I>(
&mut self,
sep: &'static str,
space_before: bool,
b: Breaks,
elts: &[T],
elts: I,
mut op: F,
) where
F: FnMut(&mut Self, &T),
I: IntoIterator<Item = &'x T>,
{
let mut it = elts.into_iter();
self.rbox(0, b);
if let Some((first, rest)) = elts.split_first() {
if let Some(first) = it.next() {
op(self, first);
for elt in rest {
for elt in it {
if space_before {
self.space();
}
@ -448,9 +451,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.end();
}
fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], op: F)
fn commasep<'x, T: 'x, F, I>(&mut self, b: Breaks, elts: I, op: F)
where
F: FnMut(&mut Self, &T),
I: IntoIterator<Item = &'x T>,
{
self.strsep(",", false, b, elts, op)
}

View File

@ -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| {

View File

@ -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)))

View File

@ -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 {

View File

@ -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

View File

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

View File

@ -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| {

View File

@ -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 =

View File

@ -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()
}
}

View File

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

View File

@ -318,7 +318,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)
}
@ -342,9 +342,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))
}

View File

@ -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, ()> {

View File

@ -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()
}
@ -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)
}
}

View File

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

View File

@ -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)
}
@ -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];

View File

@ -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()),

View File

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

View File

@ -45,14 +45,14 @@ impl<T: Copy> AppendOnlyVec<T> {
self.vec.read().get(i).copied()
}
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> + '_ {
pub fn iter_enumerated(&self) -> impl Iterator<Item = (usize, T)> {
(0..)
.map(|i| (i, self.get(i)))
.take_while(|(_, o)| o.is_some())
.filter_map(|(i, o)| Some((i, o?)))
}
pub fn iter(&self) -> impl Iterator<Item = T> + '_ {
pub fn iter(&self) -> impl Iterator<Item = T> {
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten()
}
}

View File

@ -363,7 +363,7 @@ impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
/// Lists all the base edges in the graph: the initial _non-transitive_ set of element
/// relations, which will be later used as the basis for the transitive closure computation.
pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> + '_ {
pub fn base_edges(&self) -> impl Iterator<Item = (T, T)> {
self.edges
.iter()
.map(move |edge| (self.elements[edge.source.0], self.elements[edge.target.0]))

View File

@ -31,7 +31,7 @@ impl<T> pm::bridge::server::MessagePipe<T> for MessagePipe<T> {
}
}
fn exec_strategy(ecx: &ExtCtxt<'_>) -> impl pm::bridge::server::ExecutionStrategy + use<> {
fn exec_strategy(ecx: &ExtCtxt<'_>) -> impl pm::bridge::server::ExecutionStrategy + 'static {
pm::bridge::server::MaybeCrossThread::<MessagePipe<_>>::new(
ecx.sess.opts.unstable_opts.proc_macro_execution_strategy
== ProcMacroExecutionStrategy::CrossThread,

View File

@ -93,7 +93,7 @@ impl DefPathTable {
pub fn enumerated_keys_and_path_hashes(
&self,
) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator + '_ {
) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator {
self.index_to_key
.iter_enumerated()
.map(move |(index, key)| (index, key, self.def_path_hash(index)))

View File

@ -60,7 +60,7 @@ impl LanguageItems {
self.reverse_items.get(&def_id).copied()
}
pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> + '_ {
pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> {
self.items
.iter()
.enumerate()

View File

@ -20,7 +20,6 @@ use std::ops::Bound;
use rustc_abi::ExternAbi;
use rustc_ast::Recovered;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{
@ -1690,10 +1689,10 @@ fn polarity_of_impl(
/// the lifetimes that are declared. For fns or methods, we have to
/// screen out those that do not appear in any where-clauses etc using
/// `resolve_lifetime::early_bound_lifetimes`.
fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
fn early_bound_lifetimes_from_generics<'a, 'tcx>(
tcx: TyCtxt<'tcx>,
generics: &'a hir::Generics<'a>,
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> + Captures<'tcx> {
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> {
generics.params.iter().filter(move |param| match param.kind {
GenericParamKind::Lifetime { .. } => !tcx.is_late_bound(param.hir_id),
_ => false,

View File

@ -160,7 +160,7 @@ enum Scope<'a> {
impl<'a> Scope<'a> {
// A helper for debugging scopes without printing parent scopes
fn debug_truncated(&'a self) -> impl fmt::Debug + 'a {
fn debug_truncated(&self) -> impl fmt::Debug {
fmt::from_fn(move |f| match self {
Self::Binder { bound_vars, scope_type, hir_id, where_bound_origin, s: _ } => f
.debug_struct("Binder")
@ -2159,10 +2159,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
/// Walk the generics of the item for a trait bound whose self type
/// corresponds to the expected res, and return the trait def id.
fn for_each_trait_bound_on_res(
&self,
expected_res: Res,
) -> impl Iterator<Item = DefId> + use<'tcx, '_> {
fn for_each_trait_bound_on_res(&self, expected_res: Res) -> impl Iterator<Item = DefId> {
std::iter::from_coroutine(
#[coroutine]
move || {

View File

@ -18,7 +18,8 @@ use rustc_ast_pretty::pprust::state::MacHeader;
use rustc_ast_pretty::pprust::{Comments, PrintState};
use rustc_hir::{
BindingMode, ByRef, ConstArgKind, GenericArg, GenericBound, GenericParam, GenericParamKind,
HirId, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term, TyPatKind,
HirId, ImplicitSelfKind, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term,
TyPatKind,
};
use rustc_span::source_map::SourceMap;
use rustc_span::{FileName, Ident, Span, Symbol, kw};
@ -2086,6 +2087,28 @@ impl<'a> State<'a> {
self.print_pat(arg.pat);
}
fn print_implicit_self(&mut self, implicit_self_kind: &hir::ImplicitSelfKind) {
match implicit_self_kind {
ImplicitSelfKind::Imm => {
self.word("self");
}
ImplicitSelfKind::Mut => {
self.print_mutability(hir::Mutability::Mut, false);
self.word("self");
}
ImplicitSelfKind::RefImm => {
self.word("&");
self.word("self");
}
ImplicitSelfKind::RefMut => {
self.word("&");
self.print_mutability(hir::Mutability::Mut, false);
self.word("self");
}
ImplicitSelfKind::None => unreachable!(),
}
}
fn print_arm(&mut self, arm: &hir::Arm<'_>) {
// I have no idea why this check is necessary, but here it
// is :(
@ -2151,27 +2174,33 @@ impl<'a> State<'a> {
// Make sure we aren't supplied *both* `arg_names` and `body_id`.
assert!(arg_names.is_empty() || body_id.is_none());
let mut i = 0;
let mut print_arg = |s: &mut Self| {
if let Some(arg_name) = arg_names.get(i) {
s.word(arg_name.to_string());
s.word(":");
s.space();
} else if let Some(body_id) = body_id {
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
s.word(":");
s.space();
let mut print_arg = |s: &mut Self, ty: Option<&hir::Ty<'_>>| {
if i == 0 && decl.implicit_self.has_implicit_self() {
s.print_implicit_self(&decl.implicit_self);
} else {
if let Some(arg_name) = arg_names.get(i) {
s.word(arg_name.to_string());
s.word(":");
s.space();
} else if let Some(body_id) = body_id {
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
s.word(":");
s.space();
}
if let Some(ty) = ty {
s.print_type(ty);
}
}
i += 1;
};
self.commasep(Inconsistent, decl.inputs, |s, ty| {
s.ibox(INDENT_UNIT);
print_arg(s);
s.print_type(ty);
print_arg(s, Some(ty));
s.end();
});
if decl.c_variadic {
self.word(", ");
print_arg(self);
print_arg(self, None);
self.word("...");
}
self.pclose();
@ -2284,7 +2313,9 @@ impl<'a> State<'a> {
GenericBound::Use(args, _) => {
self.word("use <");
self.commasep(Inconsistent, args, |s, arg| s.print_precise_capturing_arg(*arg));
self.commasep(Inconsistent, *args, |s, arg| {
s.print_precise_capturing_arg(*arg)
});
self.word(">");
}
@ -2300,10 +2331,23 @@ impl<'a> State<'a> {
}
fn print_generic_params(&mut self, generic_params: &[GenericParam<'_>]) {
if !generic_params.is_empty() {
let is_lifetime_elided = |generic_param: &GenericParam<'_>| {
matches!(
generic_param.kind,
GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided(_) }
)
};
// We don't want to show elided lifetimes as they are compiler-inserted and not
// expressible in surface level Rust.
if !generic_params.is_empty() && !generic_params.iter().all(is_lifetime_elided) {
self.word("<");
self.commasep(Inconsistent, generic_params, |s, param| s.print_generic_param(param));
self.commasep(
Inconsistent,
generic_params.iter().filter(|gp| !is_lifetime_elided(gp)),
|s, param| s.print_generic_param(param),
);
self.word(">");
}

View File

@ -1666,7 +1666,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
/// Iterates through all the columns set to true in a given row of
/// the matrix.
pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_ {
pub fn iter(&self, row: R) -> impl Iterator<Item = C> {
self.row(row).into_iter().flat_map(|r| r.iter())
}

View File

@ -51,7 +51,7 @@ impl<I: Idx> IntervalSet<I> {
self.map.clear();
}
pub fn iter(&self) -> impl Iterator<Item = I> + '_
pub fn iter(&self) -> impl Iterator<Item = I>
where
I: Step,
{
@ -59,7 +59,7 @@ impl<I: Idx> IntervalSet<I> {
}
/// Iterates through intervals stored in the set, in order.
pub fn iter_intervals(&self) -> impl Iterator<Item = std::ops::Range<I>> + '_
pub fn iter_intervals(&self) -> impl Iterator<Item = std::ops::Range<I>>
where
I: Step,
{

View File

@ -63,9 +63,7 @@ impl<I: Idx, T> IndexSlice<I, T> {
}
#[inline]
pub fn iter_enumerated(
&self,
) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_ {
pub fn iter_enumerated(&self) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator {
self.raw.iter().enumerate().map(|(n, t)| (I::new(n), t))
}
@ -84,7 +82,7 @@ impl<I: Idx, T> IndexSlice<I, T> {
#[inline]
pub fn iter_enumerated_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_ {
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator {
self.raw.iter_mut().enumerate().map(|(n, t)| (I::new(n), t))
}

View File

@ -132,7 +132,7 @@ impl<I: Idx, T> IndexVec<I, T> {
}
#[inline]
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> + '_ {
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> {
self.raw.drain(range)
}
@ -140,7 +140,7 @@ impl<I: Idx, T> IndexVec<I, T> {
pub fn drain_enumerated<R: RangeBounds<usize>>(
&mut self,
range: R,
) -> impl Iterator<Item = (I, T)> + '_ {
) -> impl Iterator<Item = (I, T)> {
let begin = match range.start_bound() {
std::ops::Bound::Included(i) => *i,
std::ops::Bound::Excluded(i) => i.checked_add(1).unwrap(),

View File

@ -10,7 +10,6 @@
use std::fmt::Debug;
use std::iter;
use rustc_data_structures::captures::Captures;
use rustc_index::{Idx, IndexVec};
use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::mir::ConstraintCategory;
@ -541,13 +540,13 @@ impl<'tcx> InferCtxt<'tcx> {
/// Converts the region constraints resulting from a query into an
/// iterator of obligations.
fn query_outlives_constraints_into_obligations<'a>(
&'a self,
cause: &'a ObligationCause<'tcx>,
fn query_outlives_constraints_into_obligations(
&self,
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
uninstantiated_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
result_args: &'a CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
uninstantiated_region_constraints: &[QueryOutlivesConstraint<'tcx>],
result_args: &CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> {
uninstantiated_region_constraints.iter().map(move |&constraint| {
let predicate = instantiate_value(self.tcx, result_args, constraint);
self.query_outlives_constraint_to_obligation(predicate, cause.clone(), param_env)

View File

@ -38,7 +38,7 @@ pub struct FreeRegionMap<'tcx> {
}
impl<'tcx> FreeRegionMap<'tcx> {
pub fn elements(&self) -> impl Iterator<Item = Region<'tcx>> + '_ {
pub fn elements(&self) -> impl Iterator<Item = Region<'tcx>> {
self.relation.elements().copied()
}

View File

@ -15,7 +15,6 @@ use region_constraints::{
};
pub use relate::StructurallyRelateAliases;
pub use relate::combine::PredicateEmittingRelation;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
use rustc_data_structures::unify as ut;
@ -233,7 +232,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
// while looping through this.
pub fn iter_opaque_types(
&self,
) -> impl Iterator<Item = (ty::OpaqueTypeKey<'tcx>, ty::OpaqueHiddenType<'tcx>)> + '_ {
) -> impl Iterator<Item = (ty::OpaqueTypeKey<'tcx>, ty::OpaqueHiddenType<'tcx>)> {
self.opaque_type_storage.opaque_types.iter().map(|(&k, &v)| (k, v))
}
}
@ -1295,9 +1294,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// The returned function is used in a fast path. If it returns `true` the variable is
/// unchanged, `false` indicates that the status is unknown.
#[inline]
pub fn is_ty_infer_var_definitely_unchanged<'a>(
&'a self,
) -> (impl Fn(TyOrConstInferVar) -> bool + Captures<'tcx> + 'a) {
pub fn is_ty_infer_var_definitely_unchanged(&self) -> impl Fn(TyOrConstInferVar) -> bool {
// This hoists the borrow/release out of the loop body.
let inner = self.inner.try_borrow();

View File

@ -20,7 +20,7 @@ pub(crate) mod verify;
#[instrument(level = "debug", skip(param_env), ret)]
pub fn explicit_outlives_bounds<'tcx>(
param_env: ty::ParamEnv<'tcx>,
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
) -> impl Iterator<Item = OutlivesBound<'tcx>> {
param_env
.caller_bounds()
.into_iter()

View File

@ -291,7 +291,7 @@ pub fn validate_raw_str(input: &str, prefix_len: u32) -> Result<(), RawStrError>
}
/// Creates an iterator that produces tokens from the input string.
pub fn tokenize(input: &str) -> impl Iterator<Item = Token> + '_ {
pub fn tokenize(input: &str) -> impl Iterator<Item = Token> {
let mut cursor = Cursor::new(input);
std::iter::from_fn(move || {
let token = cursor.advance_token();

View File

@ -139,9 +139,7 @@ impl LintStore {
&self.lints
}
pub fn get_lint_groups<'t>(
&'t self,
) -> impl Iterator<Item = (&'static str, Vec<LintId>, bool)> + 't {
pub fn get_lint_groups(&self) -> impl Iterator<Item = (&'static str, Vec<LintId>, bool)> {
self.lint_groups
.iter()
.filter(|(_, LintGroup { depr, .. })| {

View File

@ -1587,7 +1587,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
impl<'a, 'b, 'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for FnPtrFinder<'a, 'b, 'tcx> {
type Result = ControlFlow<Ty<'tcx>>;
type Result = ();
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
if let ty::FnPtr(_, hdr) = ty.kind()

View File

@ -8,7 +8,6 @@ use std::{io, iter, mem};
pub(super) use cstore_impl::provide;
use proc_macro::bridge::client::ProcMacro;
use rustc_ast as ast;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::owned_slice::OwnedSlice;
@ -963,14 +962,14 @@ impl CrateRoot {
pub(crate) fn decode_crate_deps<'a>(
&self,
metadata: &'a MetadataBlob,
) -> impl ExactSizeIterator<Item = CrateDep> + Captures<'a> {
) -> impl ExactSizeIterator<Item = CrateDep> {
self.crate_deps.decode(metadata)
}
pub(crate) fn decode_target_modifiers<'a>(
&self,
metadata: &'a MetadataBlob,
) -> impl ExactSizeIterator<Item = TargetModifier> + Captures<'a> {
) -> impl ExactSizeIterator<Item = TargetModifier> {
self.target_modifiers.decode(metadata)
}
}
@ -1276,7 +1275,7 @@ impl<'a> CrateMetadataRef<'a> {
self,
id: DefIndex,
sess: &'a Session,
) -> impl Iterator<Item = ModChild> + 'a {
) -> impl Iterator<Item = ModChild> {
iter::from_coroutine(
#[coroutine]
move || {
@ -1326,10 +1325,7 @@ impl<'a> CrateMetadataRef<'a> {
.is_some_and(|ident| ident.name == kw::SelfLower)
}
fn get_associated_item_or_field_def_ids(
self,
id: DefIndex,
) -> impl Iterator<Item = DefId> + 'a {
fn get_associated_item_or_field_def_ids(self, id: DefIndex) -> impl Iterator<Item = DefId> {
self.root
.tables
.associated_item_or_field_def_ids
@ -1380,7 +1376,7 @@ impl<'a> CrateMetadataRef<'a> {
self,
id: DefIndex,
sess: &'a Session,
) -> impl Iterator<Item = hir::Attribute> + 'a {
) -> impl Iterator<Item = hir::Attribute> {
self.root
.tables
.attributes
@ -1417,12 +1413,12 @@ impl<'a> CrateMetadataRef<'a> {
}
/// Decodes all traits in the crate (for rustdoc and rustc diagnostics).
fn get_traits(self) -> impl Iterator<Item = DefId> + 'a {
fn get_traits(self) -> impl Iterator<Item = DefId> {
self.root.traits.decode(self).map(move |index| self.local_def_id(index))
}
/// Decodes all trait impls in the crate (for rustdoc).
fn get_trait_impls(self) -> impl Iterator<Item = DefId> + 'a {
fn get_trait_impls(self) -> impl Iterator<Item = DefId> {
self.cdata.trait_impls.values().flat_map(move |impls| {
impls.decode(self).map(move |(impl_index, _)| self.local_def_id(impl_index))
})
@ -1463,7 +1459,7 @@ impl<'a> CrateMetadataRef<'a> {
}
}
fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> + 'a {
fn get_native_libraries(self, sess: &'a Session) -> impl Iterator<Item = NativeLib> {
self.root.native_libraries.decode((self, sess))
}
@ -1476,7 +1472,7 @@ impl<'a> CrateMetadataRef<'a> {
.decode((self, sess))
}
fn get_foreign_modules(self, sess: &'a Session) -> impl Iterator<Item = ForeignModule> + 'a {
fn get_foreign_modules(self, sess: &'a Session) -> impl Iterator<Item = ForeignModule> {
self.root.foreign_modules.decode((self, sess))
}
@ -1816,7 +1812,7 @@ impl<'a> CrateMetadataRef<'a> {
.decode(self)
}
fn get_doc_link_traits_in_scope(self, index: DefIndex) -> impl Iterator<Item = DefId> + 'a {
fn get_doc_link_traits_in_scope(self, index: DefIndex) -> impl Iterator<Item = DefId> {
self.root
.tables
.doc_link_traits_in_scope
@ -1887,7 +1883,7 @@ impl CrateMetadata {
cdata
}
pub(crate) fn dependencies(&self) -> impl Iterator<Item = CrateNum> + '_ {
pub(crate) fn dependencies(&self) -> impl Iterator<Item = CrateNum> {
self.dependencies.iter().copied()
}

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

@ -232,7 +232,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
f: F,
) -> Result<(), PrintError>
where
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
T: TypeFoldable<TyCtxt<'tcx>>,
{
f(value.as_ref().skip_binder(), self)
}
@ -1056,7 +1056,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
// Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
let paren_needed = fn_traits.len() > 1 || traits.len() > 0 || !has_sized_bound;
for ((bound_args, is_async), entry) in fn_traits {
for ((bound_args_and_self_ty, is_async), entry) in fn_traits {
write!(self, "{}", if first { "" } else { " + " })?;
write!(self, "{}", if paren_needed { "(" } else { "" })?;
@ -1067,7 +1067,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
};
if let Some(return_ty) = entry.return_ty {
self.wrap_binder(&bound_args, |args, cx| {
self.wrap_binder(&bound_args_and_self_ty, |(args, _), cx| {
define_scoped_cx!(cx);
p!(write("{}", tcx.item_name(trait_def_id)));
p!("(");
@ -1093,9 +1093,13 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
} else {
// Otherwise, render this like a regular trait.
traits.insert(
bound_args.map_bound(|args| ty::TraitPredicate {
bound_args_and_self_ty.map_bound(|(args, self_ty)| ty::TraitPredicate {
polarity: ty::PredicatePolarity::Positive,
trait_ref: ty::TraitRef::new(tcx, trait_def_id, [Ty::new_tup(tcx, args)]),
trait_ref: ty::TraitRef::new(
tcx,
trait_def_id,
[self_ty, Ty::new_tup(tcx, args)],
),
}),
FxIndexMap::default(),
);
@ -1229,7 +1233,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
FxIndexMap<DefId, ty::Binder<'tcx, Term<'tcx>>>,
>,
fn_traits: &mut FxIndexMap<
(ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>>, bool),
(ty::Binder<'tcx, (&'tcx ty::List<Ty<'tcx>>, Ty<'tcx>)>, bool),
OpaqueFnEntry<'tcx>,
>,
) {
@ -1249,7 +1253,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
&& let ty::Tuple(types) = *trait_pred.skip_binder().trait_ref.args.type_at(1).kind()
{
let entry = fn_traits
.entry((trait_pred.rebind(types), is_async))
.entry((trait_pred.rebind((types, trait_pred.skip_binder().self_ty())), is_async))
.or_insert_with(|| OpaqueFnEntry { kind, return_ty: None });
if kind.extends(entry.kind) {
entry.kind = kind;
@ -2379,7 +2383,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
f: C,
) -> Result<(), PrintError>
where
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
T: TypeFoldable<TyCtxt<'tcx>>,
{
self.pretty_wrap_binder(value, f)
}
@ -2633,7 +2637,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
value: &ty::Binder<'tcx, T>,
) -> Result<(T, UnordMap<ty::BoundRegion, ty::Region<'tcx>>), fmt::Error>
where
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
T: TypeFoldable<TyCtxt<'tcx>>,
{
fn name_by_region_index(
index: usize,
@ -2814,7 +2818,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
f: C,
) -> Result<(), fmt::Error>
where
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
T: TypeFoldable<TyCtxt<'tcx>>,
{
let old_region_index = self.region_index;
let (new_value, _) = self.name_all_regions(value)?;

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))

View File

@ -216,11 +216,11 @@ fn to_upvars_resolved_place_builder<'tcx>(
/// Supports only HIR projection kinds that represent a path that might be
/// captured by a closure or a coroutine, i.e., an `Index` or a `Subslice`
/// projection kinds are unsupported.
fn strip_prefix<'a, 'tcx>(
fn strip_prefix<'tcx>(
mut base_ty: Ty<'tcx>,
projections: &'a [PlaceElem<'tcx>],
projections: &[PlaceElem<'tcx>],
prefix_projections: &[HirProjection<'tcx>],
) -> impl Iterator<Item = PlaceElem<'tcx>> + 'a {
) -> impl Iterator<Item = PlaceElem<'tcx>> {
let mut iter = projections
.iter()
.copied()

View File

@ -165,12 +165,12 @@ impl<'tcx> ThirBuildCx<'tcx> {
})
}
fn explicit_params<'a>(
&'a mut self,
fn explicit_params(
&mut self,
owner_id: HirId,
fn_decl: &'tcx hir::FnDecl<'tcx>,
body: &'tcx hir::Body<'tcx>,
) -> impl Iterator<Item = Param<'tcx>> + 'a {
) -> impl Iterator<Item = Param<'tcx>> {
let fn_sig = self.typeck_results.liberated_fn_sigs()[owner_id];
body.params.iter().enumerate().map(move |(index, param)| {

View File

@ -343,7 +343,7 @@ impl<'tcx> MovePathLookup<'tcx> {
/// `MovePathIndex`es.
pub fn iter_locals_enumerated(
&self,
) -> impl DoubleEndedIterator<Item = (Local, MovePathIndex)> + '_ {
) -> impl DoubleEndedIterator<Item = (Local, MovePathIndex)> {
self.locals.iter_enumerated().filter_map(|(l, &idx)| Some((l, idx?)))
}
}

View File

@ -28,7 +28,7 @@ impl<'tcx> UnDerefer<'tcx> {
pub(crate) fn iter_projections(
&self,
place: PlaceRef<'tcx>,
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + '_ {
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> {
ProjectionIter::new(self.deref_chain(place.local), place)
}
}

View File

@ -2,7 +2,6 @@ use std::fmt::{Debug, Formatter};
use std::ops::Range;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry};
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_index::IndexVec;
@ -676,10 +675,7 @@ impl<'tcx> Map<'tcx> {
}
/// Iterate over all direct children.
fn children(
&self,
parent: PlaceIndex,
) -> impl Iterator<Item = PlaceIndex> + Captures<'_> + Captures<'tcx> {
fn children(&self, parent: PlaceIndex) -> impl Iterator<Item = PlaceIndex> {
Children::new(self, parent)
}

View File

@ -2,7 +2,6 @@ use std::cmp::Ordering;
use std::ops::{Index, IndexMut};
use std::{mem, slice};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::Dominators;
use rustc_data_structures::graph::{self, DirectedGraph, StartNode};
@ -218,7 +217,7 @@ impl CoverageGraph {
pub(crate) fn reloop_predecessors(
&self,
to_bcb: BasicCoverageBlock,
) -> impl Iterator<Item = BasicCoverageBlock> + Captures<'_> {
) -> impl Iterator<Item = BasicCoverageBlock> {
self.predecessors[to_bcb].iter().copied().filter(move |&pred| self.dominates(to_bcb, pred))
}
}

View File

@ -1,4 +1,3 @@
use rustc_data_structures::captures::Captures;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::{BasicCoverageBlock, CoverageIdsInfo, CoverageKind, MappingKind};
@ -153,7 +152,7 @@ fn coverage_ids_info<'tcx>(
fn all_coverage_in_mir_body<'a, 'tcx>(
body: &'a Body<'tcx>,
) -> impl Iterator<Item = &'a CoverageKind> + Captures<'tcx> {
) -> impl Iterator<Item = &'a CoverageKind> {
body.basic_blocks.iter().flat_map(|bb_data| &bb_data.statements).filter_map(|statement| {
match statement.kind {
StatementKind::Coverage(ref kind) if !is_inlined(body, statement) => Some(kind),

View File

@ -1,6 +1,5 @@
use std::collections::VecDeque;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::mir;
use rustc_span::{DesugaringKind, ExpnKind, MacroKind, Span};
@ -182,7 +181,7 @@ fn divide_spans_into_buckets(input_covspans: Vec<Covspan>, holes: &[Hole]) -> Ve
fn drain_front_while<'a, T>(
queue: &'a mut VecDeque<T>,
mut pred_fn: impl FnMut(&T) -> bool,
) -> impl Iterator<Item = T> + Captures<'a> {
) -> impl Iterator<Item = T> {
std::iter::from_fn(move || if pred_fn(queue.front()?) { queue.pop_front() } else { None })
}

View File

@ -172,11 +172,11 @@ impl HasBottom for ConditionSet<'_> {
}
impl<'a> ConditionSet<'a> {
fn iter(self) -> impl Iterator<Item = Condition> + 'a {
fn iter(self) -> impl Iterator<Item = Condition> {
self.0.iter().copied()
}
fn iter_matches(self, value: ScalarInt) -> impl Iterator<Item = Condition> + 'a {
fn iter_matches(self, value: ScalarInt) -> impl Iterator<Item = Condition> {
self.iter().filter(move |c| c.matches(value))
}

View File

@ -185,7 +185,7 @@ impl<'tcx> ReplacementMap<'tcx> {
fn place_fragments(
&self,
place: Place<'tcx>,
) -> Option<impl Iterator<Item = (FieldIdx, Ty<'tcx>, Local)> + '_> {
) -> Option<impl Iterator<Item = (FieldIdx, Ty<'tcx>, Local)>> {
let local = place.as_local()?;
let fields = self.fragments[local].as_ref()?;
Some(fields.iter_enumerated().filter_map(|(field, &opt_ty_local)| {

View File

@ -138,7 +138,7 @@ impl SsaLocals {
pub(super) fn assignments<'a, 'tcx>(
&'a self,
body: &'a Body<'tcx>,
) -> impl Iterator<Item = (Local, &'a Rvalue<'tcx>, Location)> + 'a {
) -> impl Iterator<Item = (Local, &'a Rvalue<'tcx>, Location)> {
self.assignment_order.iter().filter_map(|&local| {
if let Set1::One(DefLocation::Assignment(loc)) = self.assignments[local] {
let stmt = body.stmt_at(loc).left()?;

View File

@ -323,7 +323,7 @@ impl<'tcx> MonoItems<'tcx> {
self.items.entry(item.node).or_insert(item.span);
}
fn items(&self) -> impl Iterator<Item = MonoItem<'tcx>> + '_ {
fn items(&self) -> impl Iterator<Item = MonoItem<'tcx>> {
self.items.keys().cloned()
}
}

View File

@ -3125,10 +3125,11 @@ impl<'a> Parser<'a> {
let mut result = if armless {
// A pattern without a body, allowed for never patterns.
arm_body = None;
let span = lo.to(this.prev_token.span);
this.expect_one_of(&[exp!(Comma)], &[exp!(CloseBrace)]).map(|x| {
// Don't gate twice
if !pat.contains_never_pattern() {
this.psess.gated_spans.gate(sym::never_patterns, pat.span);
this.psess.gated_spans.gate(sym::never_patterns, span);
}
x
})

View File

@ -1657,7 +1657,7 @@ impl<'a> Parser<'a> {
// Debug view of the parser's token stream, up to `{lookahead}` tokens.
// Only used when debugging.
#[allow(unused)]
pub(crate) fn debug_lookahead(&self, lookahead: usize) -> impl fmt::Debug + '_ {
pub(crate) fn debug_lookahead(&self, lookahead: usize) -> impl fmt::Debug {
fmt::from_fn(move |f| {
let mut dbg_fmt = f.debug_struct("Parser"); // or at least, one view of

View File

@ -61,11 +61,11 @@ pub trait PatCx: Sized + fmt::Debug {
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;
/// The types of the fields for this constructor. The result must contain `ctor_arity()` fields.
fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a Constructor<Self>,
ty: &'a Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>;
fn ctor_sub_tys(
&self,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator;
/// The set of all the constructors for `ty`.
///

View File

@ -1,6 +1,6 @@
use crate::constructor::{Constructor, SplitConstructorSet};
use crate::pat::{DeconstructedPat, PatOrWild};
use crate::{Captures, MatchArm, PatCx};
use crate::{MatchArm, PatCx};
/// A column of patterns in a match, where a column is the intuitive notion of "subpatterns that
/// inspect the same subvalue/place".
@ -41,7 +41,7 @@ impl<'p, Cx: PatCx> PatternColumn<'p, Cx> {
pub fn head_ty(&self) -> Option<&Cx::Ty> {
self.patterns.first().map(|pat| pat.ty())
}
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> + Captures<'a> {
pub fn iter(&self) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> {
self.patterns.iter().copied()
}

View File

@ -25,7 +25,7 @@ use crate::lints::lint_nonexhaustive_missing_variants;
use crate::pat_column::PatternColumn;
use crate::rustc::print::EnumInfo;
use crate::usefulness::{PlaceValidity, compute_match_usefulness};
use crate::{Captures, PatCx, PrivateUninhabitedField, errors};
use crate::{PatCx, PrivateUninhabitedField, errors};
mod print;
@ -175,8 +175,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
&self,
ty: RevealedTy<'tcx>,
variant: &'tcx VariantDef,
) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> + Captures<'p> + Captures<'_>
{
) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> {
let ty::Adt(_, args) = ty.kind() else { bug!() };
variant.fields.iter().map(move |field| {
let ty = field.ty(self.tcx, args);
@ -203,13 +202,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
/// Returns the types of the fields for a given constructor. The result must have a length of
/// `ctor.arity()`.
pub(crate) fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a Constructor<'p, 'tcx>,
pub(crate) fn ctor_sub_tys(
&self,
ctor: &Constructor<'p, 'tcx>,
ty: RevealedTy<'tcx>,
) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)>
+ ExactSizeIterator
+ Captures<'a> {
) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)> + ExactSizeIterator {
fn reveal_and_alloc<'a, 'tcx>(
cx: &'a RustcPatCtxt<'_, 'tcx>,
iter: impl Iterator<Item = Ty<'tcx>>,
@ -936,12 +933,11 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
fn ctor_arity(&self, ctor: &crate::constructor::Constructor<Self>, ty: &Self::Ty) -> usize {
self.ctor_arity(ctor, *ty)
}
fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a crate::constructor::Constructor<Self>,
ty: &'a Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
{
fn ctor_sub_tys(
&self,
ctor: &crate::constructor::Constructor<Self>,
ty: &Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator {
self.ctor_sub_tys(ctor, *ty)
}
fn ctors_for_ty(

View File

@ -719,7 +719,7 @@ use tracing::{debug, instrument};
use self::PlaceValidity::*;
use crate::constructor::{Constructor, ConstructorSet, IntRange};
use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat};
use crate::{Captures, MatchArm, PatCx, PrivateUninhabitedField};
use crate::{MatchArm, PatCx, PrivateUninhabitedField};
#[cfg(not(feature = "rustc"))]
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
f()
@ -902,11 +902,11 @@ struct PlaceInfo<Cx: PatCx> {
impl<Cx: PatCx> PlaceInfo<Cx> {
/// Given a constructor for the current place, we return one `PlaceInfo` for each field of the
/// constructor.
fn specialize<'a>(
&'a self,
cx: &'a Cx,
ctor: &'a Constructor<Cx>,
) -> impl Iterator<Item = Self> + ExactSizeIterator + Captures<'a> {
fn specialize(
&self,
cx: &Cx,
ctor: &Constructor<Cx>,
) -> impl Iterator<Item = Self> + ExactSizeIterator {
let ctor_sub_tys = cx.ctor_sub_tys(ctor, &self.ty);
let ctor_sub_validity = self.validity.specialize(ctor);
ctor_sub_tys.map(move |(ty, PrivateUninhabitedField(private_uninhabited))| PlaceInfo {
@ -1046,13 +1046,13 @@ impl<'p, Cx: PatCx> PatStack<'p, Cx> {
self.pats[0]
}
fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Captures<'_> {
fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> {
self.pats.iter().copied()
}
// Expand the first or-pattern into its subpatterns. Only useful if the pattern is an
// or-pattern. Panics if `self` is empty.
fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> + Captures<'_> {
fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> {
self.head().expand_or_pat().into_iter().map(move |pat| {
let mut new = self.clone();
new.pats[0] = pat;
@ -1157,15 +1157,12 @@ impl<'p, Cx: PatCx> MatrixRow<'p, Cx> {
self.pats.head()
}
fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Captures<'_> {
fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> {
self.pats.iter()
}
// Expand the first or-pattern (if any) into its subpatterns. Panics if `self` is empty.
fn expand_or_pat(
&self,
parent_row: usize,
) -> impl Iterator<Item = MatrixRow<'p, Cx>> + Captures<'_> {
fn expand_or_pat(&self, parent_row: usize) -> impl Iterator<Item = MatrixRow<'p, Cx>> {
let is_or_pat = self.pats.head().is_or_pat();
self.pats.expand_or_pat().map(move |patstack| MatrixRow {
pats: patstack,
@ -1275,7 +1272,7 @@ impl<'p, Cx: PatCx> Matrix<'p, Cx> {
}
/// Iterate over the first pattern of each row.
fn heads(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone + Captures<'_> {
fn heads(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone {
self.rows().map(|r| r.head())
}

View File

@ -2,7 +2,7 @@ use rustc_pattern_analysis::constructor::{
Constructor, ConstructorSet, IntRange, MaybeInfiniteInt, RangeEnd, VariantVisibility,
};
use rustc_pattern_analysis::usefulness::{PlaceValidity, UsefulnessReport};
use rustc_pattern_analysis::{Captures, MatchArm, PatCx, PrivateUninhabitedField};
use rustc_pattern_analysis::{MatchArm, PatCx, PrivateUninhabitedField};
/// Sets up `tracing` for easier debugging. Tries to look like the `rustc` setup.
pub fn init_tracing() {
@ -156,12 +156,11 @@ impl PatCx for Cx {
ty.sub_tys(ctor).len()
}
fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a Constructor<Self>,
ty: &'a Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
{
fn ctor_sub_tys(
&self,
ctor: &Constructor<Self>,
ty: &Self::Ty,
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator {
ty.sub_tys(ctor).into_iter().map(|ty| (ty, PrivateUninhabitedField(false)))
}

View File

@ -98,7 +98,7 @@ impl SerializedDepGraph {
pub fn edge_targets_from(
&self,
source: SerializedDepNodeIndex,
) -> impl Iterator<Item = SerializedDepNodeIndex> + Clone + '_ {
) -> impl Iterator<Item = SerializedDepNodeIndex> + Clone {
let header = self.edge_list_indices[source];
let mut raw = &self.edge_list_data[header.start()..];
// Figure out where the edge list for `source` ends by getting the start index of the next

View File

@ -329,7 +329,7 @@ impl ParseSess {
self.proc_macro_quoted_spans.push(span)
}
pub fn proc_macro_quoted_spans(&self) -> impl Iterator<Item = (usize, Span)> + '_ {
pub fn proc_macro_quoted_spans(&self) -> impl Iterator<Item = (usize, Span)> {
// This is equivalent to `.iter().copied().enumerate()`, but that isn't possible for
// AppendOnlyVec, so we resort to this scheme.
self.proc_macro_quoted_spans.iter_enumerated()

View File

@ -20,12 +20,11 @@ pub struct FilesIndex(Vec<(Arc<str>, SearchPathFile)>);
impl FilesIndex {
/// Look up [SearchPathFile] by (prefix, suffix) pair.
pub fn query<'this, 'prefix, 'suffix>(
&'this self,
prefix: &'prefix str,
suffix: &'suffix str,
) -> Option<impl Iterator<Item = (String, &'this SearchPathFile)> + use<'this, 'prefix, 'suffix>>
{
pub fn query<'s>(
&'s self,
prefix: &str,
suffix: &str,
) -> Option<impl Iterator<Item = (String, &'s SearchPathFile)>> {
let start = self.0.partition_point(|(k, _)| **k < *prefix);
if start == self.0.len() {
return None;

View File

@ -1074,7 +1074,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
&self,
path: &'tcx hir::Path<'tcx>,
args: GenericArgsRef<'tcx>,
) -> impl Iterator<Item = InsertableGenericArgs<'tcx>> + 'a {
) -> impl Iterator<Item = InsertableGenericArgs<'tcx>> + 'tcx {
let tcx = self.tecx.tcx;
let have_turbofish = path.segments.iter().any(|segment| {
segment.args.is_some_and(|args| args.args.iter().any(|arg| arg.is_ty_or_const()))

View File

@ -67,9 +67,7 @@ impl<'tcx> ObligationStorage<'tcx> {
obligations
}
fn unstalled_for_select(
&mut self,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + use<'tcx> {
fn unstalled_for_select(&mut self) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'tcx {
mem::take(&mut self.pending).into_iter()
}

View File

@ -1,6 +1,5 @@
use std::marker::PhantomData;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::obligation_forest::{
Error, ForestObligation, ObligationForest, ObligationProcessor, Outcome, ProcessResult,
};
@ -900,10 +899,10 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
}
/// Returns the set of inference variables contained in `args`.
fn args_infer_vars<'a, 'tcx>(
selcx: &SelectionContext<'a, 'tcx>,
fn args_infer_vars<'tcx>(
selcx: &SelectionContext<'_, 'tcx>,
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
) -> impl Iterator<Item = TyOrConstInferVar> + Captures<'tcx> {
) -> impl Iterator<Item = TyOrConstInferVar> {
selcx
.infcx
.resolve_vars_if_possible(args)

View File

@ -200,15 +200,12 @@ impl<'tcx> Children {
}
}
fn iter_children(children: &Children) -> impl Iterator<Item = DefId> + '_ {
fn iter_children(children: &Children) -> impl Iterator<Item = DefId> {
let nonblanket = children.non_blanket_impls.iter().flat_map(|(_, v)| v.iter());
children.blanket_impls.iter().chain(nonblanket).cloned()
}
fn filtered_children(
children: &mut Children,
st: SimplifiedType,
) -> impl Iterator<Item = DefId> + '_ {
fn filtered_children(children: &mut Children, st: SimplifiedType) -> impl Iterator<Item = DefId> {
let nonblanket = children.non_blanket_impls.entry(st).or_default().iter();
children.blanket_impls.iter().chain(nonblanket).cloned()
}

View File

@ -196,7 +196,7 @@ fn own_existential_vtable_entries(tcx: TyCtxt<'_>, trait_def_id: DefId) -> &[Def
fn own_existential_vtable_entries_iter(
tcx: TyCtxt<'_>,
trait_def_id: DefId,
) -> impl Iterator<Item = DefId> + '_ {
) -> impl Iterator<Item = DefId> {
let trait_methods = tcx
.associated_items(trait_def_id)
.in_definition_order()

View File

@ -151,7 +151,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
}
}
fn fn_sig_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator<Item = Span> + '_ {
fn fn_sig_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator<Item = Span> {
let node = tcx.hir_node_by_def_id(def_id);
if let Some(decl) = node.fn_decl() {
decl.inputs.iter().map(|ty| ty.span).chain(iter::once(decl.output.span()))
@ -160,7 +160,7 @@ fn fn_sig_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator<Item = Spa
}
}
fn impl_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator<Item = Span> + '_ {
fn impl_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator<Item = Span> {
let item = tcx.hir().expect_item(def_id);
if let hir::ItemKind::Impl(impl_) = item.kind {
let trait_args = impl_

View File

@ -33,7 +33,7 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
fn non_zst_fields<'tcx, 'a>(
cx: &'a LayoutCx<'tcx>,
layout: &'a TyAndLayout<'tcx>,
) -> impl Iterator<Item = (Size, TyAndLayout<'tcx>)> + 'a {
) -> impl Iterator<Item = (Size, TyAndLayout<'tcx>)> {
(0..layout.layout.fields().count()).filter_map(|i| {
let field = layout.field(cx, i);
// Also checking `align == 1` here leads to test failures in

View File

@ -373,7 +373,7 @@ fn drop_tys_helper<'tcx>(
fn adt_consider_insignificant_dtor<'tcx>(
tcx: TyCtxt<'tcx>,
) -> impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType> + 'tcx {
) -> impl Fn(ty::AdtDef<'tcx>) -> Option<DtorType> {
move |adt_def: ty::AdtDef<'tcx>| {
let is_marked_insig = tcx.has_attr(adt_def.did(), sym::rustc_insignificant_dtor);
if is_marked_insig {

View File

@ -285,7 +285,7 @@ impl<X: Cx> NestedGoals<X> {
#[cfg_attr(feature = "nightly", rustc_lint_query_instability)]
#[allow(rustc::potential_query_instability)]
fn iter(&self) -> impl Iterator<Item = (X::Input, UsageKind)> + '_ {
fn iter(&self) -> impl Iterator<Item = (X::Input, UsageKind)> {
self.nested_goals.iter().map(|(i, p)| (*i, *p))
}

View File

@ -864,7 +864,7 @@ impl SwitchTargets {
}
/// The conditional targets which are only taken if the pattern matches the given value.
pub fn branches(&self) -> impl Iterator<Item = (u128, BasicBlockIdx)> + '_ {
pub fn branches(&self) -> impl Iterator<Item = (u128, BasicBlockIdx)> {
self.branches.iter().copied()
}

View File

@ -809,7 +809,7 @@ impl AdtDef {
}
/// Iterate over the variants in this ADT.
pub fn variants_iter(&self) -> impl Iterator<Item = VariantDef> + '_ {
pub fn variants_iter(&self) -> impl Iterator<Item = VariantDef> {
(0..self.num_variants())
.map(|idx| VariantDef { idx: VariantIdx::to_val(idx), adt_def: *self })
}

View File

@ -161,7 +161,7 @@ impl Visitable for RigidTy {
RigidTy::Slice(inner) => inner.visit(visitor),
RigidTy::RawPtr(ty, _) => ty.visit(visitor),
RigidTy::Ref(reg, ty, _) => {
reg.visit(visitor);
reg.visit(visitor)?;
ty.visit(visitor)
}
RigidTy::Adt(_, args)

View File

@ -20,7 +20,7 @@ type LocalStream = Arc<Mutex<Vec<u8>>>;
thread_local! {
/// Used by the test crate to capture the output of the print macros and panics.
static OUTPUT_CAPTURE: Cell<Option<LocalStream>> = {
static OUTPUT_CAPTURE: Cell<Option<LocalStream>> = const {
Cell::new(None)
}
}

View File

@ -1382,3 +1382,6 @@ impl<T> fmt::Debug for Receiver<T> {
f.pad("Receiver { .. }")
}
}
#[cfg(test)]
mod tests;

View File

@ -0,0 +1,14 @@
// Ensure that thread_local init with `const { 0 }` still has unique address at run-time
#[test]
fn waker_current_thread_id() {
let first = super::waker::current_thread_id();
let t = crate::thread::spawn(move || {
let second = super::waker::current_thread_id();
assert_ne!(first, second);
assert_eq!(second, super::waker::current_thread_id());
});
assert_eq!(first, super::waker::current_thread_id());
t.join().unwrap();
assert_eq!(first, super::waker::current_thread_id());
}

View File

@ -204,6 +204,6 @@ impl Drop for SyncWaker {
pub fn current_thread_id() -> usize {
// `u8` is not drop so this variable will be available during thread destruction,
// whereas `thread::current()` would not be
thread_local! { static DUMMY: u8 = 0 }
thread_local! { static DUMMY: u8 = const { 0 } }
DUMMY.with(|x| (x as *const u8).addr())
}

View File

@ -557,10 +557,13 @@ impl TcpListener {
}
pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() };
// The `accept` function will fill in the storage with the address,
// so we don't need to zero it here.
// reference: https://linux.die.net/man/2/accept4
let mut storage: mem::MaybeUninit<c::sockaddr_storage> = mem::MaybeUninit::uninit();
let mut len = mem::size_of_val(&storage) as c::socklen_t;
let sock = self.inner.accept((&raw mut storage) as *mut _, &mut len)?;
let addr = unsafe { socket_addr_from_c(&storage, len as usize)? };
let sock = self.inner.accept(storage.as_mut_ptr() as *mut _, &mut len)?;
let addr = unsafe { socket_addr_from_c(storage.as_ptr(), len as usize)? };
Ok((TcpStream { inner: sock }, addr))
}

View File

@ -322,7 +322,10 @@ impl Socket {
buf: &mut [u8],
flags: c_int,
) -> io::Result<(usize, SocketAddr)> {
let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
// The `recvfrom` function will fill in the storage with the address,
// so we don't need to zero it here.
// reference: https://linux.die.net/man/2/recvfrom
let mut storage: mem::MaybeUninit<libc::sockaddr_storage> = mem::MaybeUninit::uninit();
let mut addrlen = mem::size_of_val(&storage) as libc::socklen_t;
let n = cvt(unsafe {
@ -335,7 +338,7 @@ impl Socket {
&mut addrlen,
)
})?;
Ok((n as usize, unsafe { socket_addr_from_c(&storage, addrlen as usize)? }))
Ok((n as usize, unsafe { socket_addr_from_c(storage.as_ptr(), addrlen as usize)? }))
}
pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {

View File

@ -319,21 +319,27 @@ mod imp {
))]
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
let mut ret = None;
let mut attr: libc::pthread_attr_t = crate::mem::zeroed();
let mut attr: mem::MaybeUninit<libc::pthread_attr_t> = mem::MaybeUninit::uninit();
if !cfg!(target_os = "freebsd") {
attr = mem::MaybeUninit::zeroed();
}
#[cfg(target_os = "freebsd")]
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0);
#[cfg(target_os = "freebsd")]
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
let e = libc::pthread_attr_get_np(libc::pthread_self(), attr.as_mut_ptr());
#[cfg(not(target_os = "freebsd"))]
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
let e = libc::pthread_getattr_np(libc::pthread_self(), attr.as_mut_ptr());
if e == 0 {
let mut stackaddr = crate::ptr::null_mut();
let mut stacksize = 0;
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut stacksize), 0);
assert_eq!(
libc::pthread_attr_getstack(attr.as_ptr(), &mut stackaddr, &mut stacksize),
0
);
ret = Some(stackaddr);
}
if e == 0 || cfg!(target_os = "freebsd") {
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0);
}
ret
}
@ -509,16 +515,20 @@ mod imp {
// FIXME: I am probably not unsafe.
unsafe fn current_guard() -> Option<Range<usize>> {
let mut ret = None;
let mut attr: libc::pthread_attr_t = crate::mem::zeroed();
let mut attr: mem::MaybeUninit<libc::pthread_attr_t> = mem::MaybeUninit::uninit();
if !cfg!(target_os = "freebsd") {
attr = mem::MaybeUninit::zeroed();
}
#[cfg(target_os = "freebsd")]
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0);
#[cfg(target_os = "freebsd")]
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
let e = libc::pthread_attr_get_np(libc::pthread_self(), attr.as_mut_ptr());
#[cfg(not(target_os = "freebsd"))]
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
let e = libc::pthread_getattr_np(libc::pthread_self(), attr.as_mut_ptr());
if e == 0 {
let mut guardsize = 0;
assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
assert_eq!(libc::pthread_attr_getguardsize(attr.as_ptr(), &mut guardsize), 0);
if guardsize == 0 {
if cfg!(all(target_os = "linux", target_env = "musl")) {
// musl versions before 1.1.19 always reported guard
@ -531,7 +541,7 @@ mod imp {
}
let mut stackptr = crate::ptr::null_mut::<libc::c_void>();
let mut size = 0;
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackptr, &mut size), 0);
assert_eq!(libc::pthread_attr_getstack(attr.as_ptr(), &mut stackptr, &mut size), 0);
let stackaddr = stackptr.addr();
ret = if cfg!(any(target_os = "freebsd", target_os = "netbsd", target_os = "hurd")) {
@ -552,7 +562,7 @@ mod imp {
};
}
if e == 0 || cfg!(target_os = "freebsd") {
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0);
}
ret
}

View File

@ -49,24 +49,27 @@ impl Thread {
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
let p = Box::into_raw(Box::new(p));
let mut native: libc::pthread_t = mem::zeroed();
let mut attr: libc::pthread_attr_t = mem::zeroed();
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
let mut attr: mem::MaybeUninit<libc::pthread_attr_t> = mem::MaybeUninit::uninit();
assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0);
#[cfg(target_os = "espidf")]
if stack > 0 {
// Only set the stack if a non-zero value is passed
// 0 is used as an indication that the default stack size configured in the ESP-IDF menuconfig system should be used
assert_eq!(
libc::pthread_attr_setstacksize(&mut attr, cmp::max(stack, min_stack_size(&attr))),
libc::pthread_attr_setstacksize(
attr.as_mut_ptr(),
cmp::max(stack, min_stack_size(&attr))
),
0
);
}
#[cfg(not(target_os = "espidf"))]
{
let stack_size = cmp::max(stack, min_stack_size(&attr));
let stack_size = cmp::max(stack, min_stack_size(attr.as_ptr()));
match libc::pthread_attr_setstacksize(&mut attr, stack_size) {
match libc::pthread_attr_setstacksize(attr.as_mut_ptr(), stack_size) {
0 => {}
n => {
assert_eq!(n, libc::EINVAL);
@ -77,16 +80,16 @@ impl Thread {
let page_size = os::page_size();
let stack_size =
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0);
assert_eq!(libc::pthread_attr_setstacksize(attr.as_mut_ptr(), stack_size), 0);
}
};
}
let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _);
let ret = libc::pthread_create(&mut native, attr.as_ptr(), thread_start, p as *mut _);
// Note: if the thread creation fails and this assert fails, then p will
// be leaked. However, an alternative design could cause double-free
// which is clearly worse.
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0);
return if ret != 0 {
// The thread failed to start and as a result p was not consumed. Therefore, it is

View File

@ -50,7 +50,8 @@ use crate::fmt;
/// use std::cell::Cell;
/// use std::thread;
///
/// thread_local!(static FOO: Cell<u32> = Cell::new(1));
/// // explicit `const {}` block enables more efficient initialization
/// thread_local!(static FOO: Cell<u32> = const { Cell::new(1) });
///
/// assert_eq!(FOO.get(), 1);
/// FOO.set(2);
@ -138,7 +139,7 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
/// use std::cell::{Cell, RefCell};
///
/// thread_local! {
/// pub static FOO: Cell<u32> = Cell::new(1);
/// pub static FOO: Cell<u32> = const { Cell::new(1) };
///
/// static BAR: RefCell<Vec<f32>> = RefCell::new(vec![1.0, 2.0]);
/// }
@ -394,7 +395,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
/// use std::cell::Cell;
///
/// thread_local! {
/// static X: Cell<i32> = Cell::new(1);
/// static X: Cell<i32> = const { Cell::new(1) };
/// }
///
/// assert_eq!(X.get(), 1);
@ -423,7 +424,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
/// use std::cell::Cell;
///
/// thread_local! {
/// static X: Cell<Option<i32>> = Cell::new(Some(1));
/// static X: Cell<Option<i32>> = const { Cell::new(Some(1)) };
/// }
///
/// assert_eq!(X.take(), Some(1));
@ -453,7 +454,7 @@ impl<T: 'static> LocalKey<Cell<T>> {
/// use std::cell::Cell;
///
/// thread_local! {
/// static X: Cell<i32> = Cell::new(1);
/// static X: Cell<i32> = const { Cell::new(1) };
/// }
///
/// assert_eq!(X.replace(2), 1);

View File

@ -1,9 +1,14 @@
//! Handles the vendoring process for the bootstrap system.
//!
//! This module ensures that all required Cargo dependencies are gathered
//! and stored in the `<src>/<VENDOR_DIR>` directory.
use std::path::PathBuf;
use crate::core::build_steps::tool::SUBMODULES_FOR_RUSTBOOK;
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::utils::exec::command;
/// The name of the directory where vendored dependencies are stored.
pub const VENDOR_DIR: &str = "vendor";
/// Returns the cargo workspaces to vendor for `x vendor` and dist tarballs.
@ -29,11 +34,19 @@ pub fn default_paths_to_vendor(builder: &Builder<'_>) -> Vec<(PathBuf, Vec<&'sta
.collect()
}
/// Defines the vendoring step in the bootstrap process.
///
/// This step executes `cargo vendor` to collect all dependencies
/// and store them in the `<src>/<VENDOR_DIR>` directory.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub(crate) struct Vendor {
/// Additional paths to synchronize during vendoring.
pub(crate) sync_args: Vec<PathBuf>,
/// Determines whether vendored dependencies use versioned directories.
pub(crate) versioned_dirs: bool,
/// The root directory of the source code.
pub(crate) root_dir: PathBuf,
/// The target directory for storing vendored dependencies.
pub(crate) output_dir: PathBuf,
}
@ -55,6 +68,10 @@ impl Step for Vendor {
});
}
/// Executes the vendoring process.
///
/// This function runs `cargo vendor` and ensures all required submodules
/// are initialized before vendoring begins.
fn run(self, builder: &Builder<'_>) -> Self::Output {
builder.info(&format!("Vendoring sources to {:?}", self.root_dir));
@ -94,6 +111,7 @@ impl Step for Vendor {
}
}
/// Stores the result of the vendoring step.
#[derive(Debug, Clone)]
pub(crate) struct VendorOutput {
pub(crate) config: String,

Some files were not shown because too many files have changed in this diff Show More