Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,10 @@ impl<T: [const] Destruct> const Drop for Guard<'_, T> {
/// dropped.
///
/// Used for [`Iterator::next_chunk`].
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
#[inline]
pub(crate) fn iter_next_chunk<T, const N: usize>(
iter: &mut impl Iterator<Item = T>,
pub(crate) const fn iter_next_chunk<T, const N: usize>(
iter: &mut impl [const] Iterator<Item = T>,
) -> Result<[T; N], IntoIter<T, N>> {
let mut array = [const { MaybeUninit::uninit() }; N];
let r = iter_next_chunk_erased(&mut array, iter);
Expand All @@ -1026,10 +1027,11 @@ pub(crate) fn iter_next_chunk<T, const N: usize>(
///
/// Unfortunately this loop has two exit conditions, the buffer filling up
/// or the iterator running out of items, making it tend to optimize poorly.
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
#[inline]
fn iter_next_chunk_erased<T>(
const fn iter_next_chunk_erased<T>(
buffer: &mut [MaybeUninit<T>],
iter: &mut impl Iterator<Item = T>,
iter: &mut impl [const] Iterator<Item = T>,
) -> Result<(), usize> {
// if `Iterator::next` panics, this guard will drop already initialized items
let mut guard = Guard { array_mut: buffer, initialized: 0 };
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/array_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
I: Iterator,
{
#[track_caller]
pub(in crate::iter) fn new(iter: I) -> Self {
pub(in crate::iter) const fn new(iter: I) -> Self {
assert!(N != 0, "chunk size must be non-zero");
Self { iter, remainder: None }
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Chain<A, B> {
b: Option<B>,
}
impl<A, B> Chain<A, B> {
pub(in super::super) fn new(a: A, b: B) -> Chain<A, B> {
pub(in super::super) const fn new(a: A, b: B) -> Chain<A, B> {
Chain { a: Some(a), b: Some(b) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/cloned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Cloned<I> {
}

impl<I> Cloned<I> {
pub(in crate::iter) fn new(it: I) -> Cloned<I> {
pub(in crate::iter) const fn new(it: I) -> Cloned<I> {
Cloned { it }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Copied<I> {
}

impl<I> Copied<I> {
pub(in crate::iter) fn new(it: I) -> Copied<I> {
pub(in crate::iter) const fn new(it: I) -> Copied<I> {
Copied { it }
}

Expand Down
6 changes: 5 additions & 1 deletion library/core/src/iter/adapters/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ pub struct Cycle<I> {
}

impl<I: Clone> Cycle<I> {
pub(in crate::iter) fn new(iter: I) -> Cycle<I> {
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
pub(in crate::iter) const fn new(iter: I) -> Cycle<I>
where
I: [const] Clone,
{
Cycle { orig: iter.clone(), iter }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Enumerate<I> {
count: usize,
}
impl<I> Enumerate<I> {
pub(in crate::iter) fn new(iter: I) -> Enumerate<I> {
pub(in crate::iter) const fn new(iter: I) -> Enumerate<I> {
Enumerate { iter, count: 0 }
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Filter<I, P> {
predicate: P,
}
impl<I, P> Filter<I, P> {
pub(in crate::iter) fn new(iter: I, predicate: P) -> Filter<I, P> {
pub(in crate::iter) const fn new(iter: I, predicate: P) -> Filter<I, P> {
Filter { iter, predicate }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct FilterMap<I, F> {
f: F,
}
impl<I, F> FilterMap<I, F> {
pub(in crate::iter) fn new(iter: I, f: F) -> FilterMap<I, F> {
pub(in crate::iter) const fn new(iter: I, f: F) -> FilterMap<I, F> {
FilterMap { iter, f }
}
}
Expand Down
12 changes: 10 additions & 2 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ pub struct Flatten<I: Iterator<Item: IntoIterator>> {
}

impl<I: Iterator<Item: IntoIterator>> Flatten<I> {
pub(in super::super) fn new(iter: I) -> Flatten<I> {
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
pub(in super::super) const fn new(iter: I) -> Flatten<I>
where
I: [const] Iterator,
{
Flatten { inner: FlattenCompat::new(iter) }
}
}
Expand Down Expand Up @@ -363,7 +367,11 @@ where
I: Iterator,
{
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
fn new(iter: I) -> FlattenCompat<I, U> {
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
const fn new(iter: I) -> FlattenCompat<I, U>
where
I: [const] Iterator,
{
FlattenCompat { iter: iter.fuse(), frontiter: None, backiter: None }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Fuse<I> {
iter: Option<I>,
}
impl<I> Fuse<I> {
pub(in crate::iter) fn new(iter: I) -> Fuse<I> {
pub(in crate::iter) const fn new(iter: I) -> Fuse<I> {
Fuse { iter: Some(iter) }
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Inspect<I, F> {
f: F,
}
impl<I, F> Inspect<I, F> {
pub(in crate::iter) fn new(iter: I, f: F) -> Inspect<I, F> {
pub(in crate::iter) const fn new(iter: I, f: F) -> Inspect<I, F> {
Inspect { iter, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/map_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct MapWhile<I, P> {
}

impl<I, P> MapWhile<I, P> {
pub(in crate::iter) fn new(iter: I, predicate: P) -> MapWhile<I, P> {
pub(in crate::iter) const fn new(iter: I, predicate: P) -> MapWhile<I, P> {
MapWhile { iter, predicate }
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/iter/adapters/map_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Buffer<T, const N: usize> {
}

impl<I: Iterator, F, const N: usize> MapWindows<I, F, N> {
pub(in crate::iter) fn new(iter: I, f: F) -> Self {
pub(in crate::iter) const fn new(iter: I, f: F) -> Self {
assert!(N != 0, "array in `Iterator::map_windows` must contain more than 0 elements");

// Only ZST arrays' length can be so large.
Expand All @@ -63,7 +63,7 @@ impl<I: Iterator, F, const N: usize> MapWindows<I, F, N> {

impl<I: Iterator, const N: usize> MapWindowsInner<I, N> {
#[inline]
fn new(iter: I) -> Self {
const fn new(iter: I) -> Self {
Self { iter: Some(iter), buffer: None }
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/peekable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Peekable<I: Iterator> {
}

impl<I: Iterator> Peekable<I> {
pub(in crate::iter) fn new(iter: I) -> Peekable<I> {
pub(in crate::iter) const fn new(iter: I) -> Peekable<I> {
Peekable { iter, peeked: None }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/rev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Rev<T> {
}

impl<T> Rev<T> {
pub(in crate::iter) fn new(iter: T) -> Rev<T> {
pub(in crate::iter) const fn new(iter: T) -> Rev<T> {
Rev { iter }
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Scan<I, St, F> {
}

impl<I, St, F> Scan<I, St, F> {
pub(in crate::iter) fn new(iter: I, state: St, f: F) -> Scan<I, St, F> {
pub(in crate::iter) const fn new(iter: I, state: St, f: F) -> Scan<I, St, F> {
Scan { iter, state, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Skip<I> {
}

impl<I> Skip<I> {
pub(in crate::iter) fn new(iter: I, n: usize) -> Skip<I> {
pub(in crate::iter) const fn new(iter: I, n: usize) -> Skip<I> {
Skip { iter, n }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/skip_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct SkipWhile<I, P> {
}

impl<I, P> SkipWhile<I, P> {
pub(in crate::iter) fn new(iter: I, predicate: P) -> SkipWhile<I, P> {
pub(in crate::iter) const fn new(iter: I, predicate: P) -> SkipWhile<I, P> {
SkipWhile { iter, flag: false, predicate }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Take<I> {
}

impl<I> Take<I> {
pub(in crate::iter) fn new(iter: I, n: usize) -> Take<I> {
pub(in crate::iter) const fn new(iter: I, n: usize) -> Take<I> {
Take { iter, n }
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/take_while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct TakeWhile<I, P> {
}

impl<I, P> TakeWhile<I, P> {
pub(in crate::iter) fn new(iter: I, predicate: P) -> TakeWhile<I, P> {
pub(in crate::iter) const fn new(iter: I, predicate: P) -> TakeWhile<I, P> {
TakeWhile { iter, flag: false, predicate }
}
}
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/iter/traits/accum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use crate::num::{Saturating, Wrapping};
/// [`sum()`]: Iterator::sum
/// [`FromIterator`]: iter::FromIterator
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
#[diagnostic::on_unimplemented(
message = "a value of type `{Self}` cannot be made by summing an iterator over elements of type `{A}`",
label = "value of type `{Self}` cannot be made by summing a `std::iter::Iterator<Item={A}>`"
)]
pub trait Sum<A = Self>: Sized {
pub const trait Sum<A = Self>: Sized {
/// Takes an iterator and generates `Self` from the elements by "summing up"
/// the items.
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
Expand All @@ -31,11 +32,12 @@ pub trait Sum<A = Self>: Sized {
/// [`product()`]: Iterator::product
/// [`FromIterator`]: iter::FromIterator
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
#[diagnostic::on_unimplemented(
message = "a value of type `{Self}` cannot be made by multiplying all elements of type `{A}` from an iterator",
label = "value of type `{Self}` cannot be made by multiplying all elements from a `std::iter::Iterator<Item={A}>`"
)]
pub trait Product<A = Self>: Sized {
pub const trait Product<A = Self>: Sized {
/// Takes an iterator and generates `Self` from the elements by multiplying
/// the items.
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
Expand Down
Loading
Loading