Skip to content

Commit eba5951

Browse files
committed
de-non_const some iterator methods
1 parent e6b64a2 commit eba5951

27 files changed

+94
-108
lines changed

library/core/src/array/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,10 @@ impl<T: [const] Destruct> const Drop for Guard<'_, T> {
10051005
/// dropped.
10061006
///
10071007
/// Used for [`Iterator::next_chunk`].
1008+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
10081009
#[inline]
1009-
pub(crate) fn iter_next_chunk<T, const N: usize>(
1010-
iter: &mut impl Iterator<Item = T>,
1010+
pub(crate) const fn iter_next_chunk<T, const N: usize>(
1011+
iter: &mut impl [const] Iterator<Item = T>,
10111012
) -> Result<[T; N], IntoIter<T, N>> {
10121013
let mut array = [const { MaybeUninit::uninit() }; N];
10131014
let r = iter_next_chunk_erased(&mut array, iter);
@@ -1028,10 +1029,11 @@ pub(crate) fn iter_next_chunk<T, const N: usize>(
10281029
///
10291030
/// Unfortunately this loop has two exit conditions, the buffer filling up
10301031
/// or the iterator running out of items, making it tend to optimize poorly.
1032+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
10311033
#[inline]
1032-
fn iter_next_chunk_erased<T>(
1034+
const fn iter_next_chunk_erased<T>(
10331035
buffer: &mut [MaybeUninit<T>],
1034-
iter: &mut impl Iterator<Item = T>,
1036+
iter: &mut impl [const] Iterator<Item = T>,
10351037
) -> Result<(), usize> {
10361038
// if `Iterator::next` panics, this guard will drop already initialized items
10371039
let mut guard = Guard { array_mut: buffer, initialized: 0 };

library/core/src/iter/adapters/array_chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ where
2626
I: Iterator,
2727
{
2828
#[track_caller]
29-
pub(in crate::iter) fn new(iter: I) -> Self {
29+
pub(in crate::iter) const fn new(iter: I) -> Self {
3030
assert!(N != 0, "chunk size must be non-zero");
3131
Self { iter, remainder: None }
3232
}

library/core/src/iter/adapters/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Chain<A, B> {
3333
b: Option<B>,
3434
}
3535
impl<A, B> Chain<A, B> {
36-
pub(in super::super) fn new(a: A, b: B) -> Chain<A, B> {
36+
pub(in super::super) const fn new(a: A, b: B) -> Chain<A, B> {
3737
Chain { a: Some(a), b: Some(b) }
3838
}
3939
}

library/core/src/iter/adapters/cloned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Cloned<I> {
2020
}
2121

2222
impl<I> Cloned<I> {
23-
pub(in crate::iter) fn new(it: I) -> Cloned<I> {
23+
pub(in crate::iter) const fn new(it: I) -> Cloned<I> {
2424
Cloned { it }
2525
}
2626
}

library/core/src/iter/adapters/copied.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Copied<I> {
2121
}
2222

2323
impl<I> Copied<I> {
24-
pub(in crate::iter) fn new(it: I) -> Copied<I> {
24+
pub(in crate::iter) const fn new(it: I) -> Copied<I> {
2525
Copied { it }
2626
}
2727

library/core/src/iter/adapters/cycle.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ pub struct Cycle<I> {
1818
}
1919

2020
impl<I: Clone> Cycle<I> {
21-
pub(in crate::iter) fn new(iter: I) -> Cycle<I> {
21+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
22+
pub(in crate::iter) const fn new(iter: I) -> Cycle<I>
23+
where
24+
I: [const] Clone,
25+
{
2226
Cycle { orig: iter.clone(), iter }
2327
}
2428
}

library/core/src/iter/adapters/enumerate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Enumerate<I> {
2020
count: usize,
2121
}
2222
impl<I> Enumerate<I> {
23-
pub(in crate::iter) fn new(iter: I) -> Enumerate<I> {
23+
pub(in crate::iter) const fn new(iter: I) -> Enumerate<I> {
2424
Enumerate { iter, count: 0 }
2525
}
2626

library/core/src/iter/adapters/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Filter<I, P> {
2424
predicate: P,
2525
}
2626
impl<I, P> Filter<I, P> {
27-
pub(in crate::iter) fn new(iter: I, predicate: P) -> Filter<I, P> {
27+
pub(in crate::iter) const fn new(iter: I, predicate: P) -> Filter<I, P> {
2828
Filter { iter, predicate }
2929
}
3030
}

library/core/src/iter/adapters/filter_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct FilterMap<I, F> {
2020
f: F,
2121
}
2222
impl<I, F> FilterMap<I, F> {
23-
pub(in crate::iter) fn new(iter: I, f: F) -> FilterMap<I, F> {
23+
pub(in crate::iter) const fn new(iter: I, f: F) -> FilterMap<I, F> {
2424
FilterMap { iter, f }
2525
}
2626
}

library/core/src/iter/adapters/flatten.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ pub struct Flatten<I: Iterator<Item: IntoIterator>> {
186186
}
187187

188188
impl<I: Iterator<Item: IntoIterator>> Flatten<I> {
189-
pub(in super::super) fn new(iter: I) -> Flatten<I> {
189+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
190+
pub(in super::super) const fn new(iter: I) -> Flatten<I>
191+
where
192+
I: [const] Iterator,
193+
{
190194
Flatten { inner: FlattenCompat::new(iter) }
191195
}
192196
}
@@ -363,7 +367,11 @@ where
363367
I: Iterator,
364368
{
365369
/// Adapts an iterator by flattening it, for use in `flatten()` and `flat_map()`.
366-
fn new(iter: I) -> FlattenCompat<I, U> {
370+
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
371+
const fn new(iter: I) -> FlattenCompat<I, U>
372+
where
373+
I: [const] Iterator,
374+
{
367375
FlattenCompat { iter: iter.fuse(), frontiter: None, backiter: None }
368376
}
369377
}

0 commit comments

Comments
 (0)