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
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/array_chunks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::array;
use crate::iter::adapters::SourceIter;
use crate::iter::{FusedIterator, InPlaceIterable, TrustedFused, TrustedRandomAccessNoCoerce};
use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::{ControlFlow, NeverShortCircuit, Try};

Expand Down
14 changes: 8 additions & 6 deletions library/core/src/iter/adapters/map_while.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::fmt;
use crate::iter::InPlaceIterable;
use crate::iter::adapters::SourceIter;
use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};

Expand Down Expand Up @@ -33,9 +34,10 @@ impl<I: fmt::Debug, P> fmt::Debug for MapWhile<I, P> {
}

#[stable(feature = "iter_map_while", since = "1.57.0")]
impl<B, I: Iterator, P> Iterator for MapWhile<I, P>
#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
const impl<B, I: [const] Iterator, P> Iterator for MapWhile<I, P>
where
P: FnMut(I::Item) -> Option<B>,
P: [const] FnMut(I::Item) -> Option<B>,
{
type Item = B;

Expand All @@ -55,18 +57,18 @@ where
fn try_fold<Acc, Fold, R>(&mut self, init: Acc, mut fold: Fold) -> R
where
Self: Sized,
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Output = Acc>,
Fold: [const] FnMut(Acc, Self::Item) -> R + [const] Destruct,
R: [const] Try<Output = Acc>,
{
let Self { iter, predicate } = self;
iter.try_fold(init, |acc, x| match predicate(x) {
iter.try_fold(init, const |acc, x| match predicate(x) {
Some(item) => ControlFlow::from_try(fold(acc, item)),
None => ControlFlow::Break(try { acc }),
})
.into_try()
}

impl_fold_via_try_fold! { fold -> try_fold }
impl_fold_via_try_fold! { const fold -> try_fold }
}

#[unstable(issue = "none", feature = "inplace_iteration")]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::iter::InPlaceIterable;
use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try};

Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/scan.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::fmt;
use crate::iter::InPlaceIterable;
use crate::iter::adapters::SourceIter;
use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};

Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::iter::{
FusedIterator, InPlaceIterable, TrustedFused, TrustedLen, TrustedRandomAccess,
TrustedRandomAccessNoCoerce,
};
use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};

Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/take_while.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::fmt;
use crate::iter::adapters::SourceIter;
use crate::iter::{FusedIterator, InPlaceIterable, TrustedFused};
use crate::marker::Destruct;
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};

Expand Down
43 changes: 20 additions & 23 deletions library/core/src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,30 +357,27 @@

// This needs to be up here in order to be usable in the child modules
macro_rules! impl_fold_via_try_fold {
(fold -> try_fold) => {
impl_fold_via_try_fold! { @internal fold -> try_fold }
};
(rfold -> try_rfold) => {
impl_fold_via_try_fold! { @internal rfold -> try_rfold }
};
(spec_fold -> spec_try_fold) => {
impl_fold_via_try_fold! { @internal spec_fold -> spec_try_fold }
};
(spec_rfold -> spec_try_rfold) => {
impl_fold_via_try_fold! { @internal spec_rfold -> spec_try_rfold }
};
(@internal $fold:ident -> $try_fold:ident) => {
#[inline]
fn $fold<AAA, FFF>(mut self, init: AAA, fold: FFF) -> AAA
where
FFF: FnMut(AAA, Self::Item) -> AAA,
{
use crate::ops::NeverShortCircuit;
(const $fold:ident -> $try_fold:ident) => {
impl_fold_via_try_fold!(@internal [[const]] $fold -> $try_fold);
};
($fold:ident -> $try_fold:ident) => {
impl_fold_via_try_fold!(@internal [] $fold -> $try_fold);
};

self.$try_fold(init, NeverShortCircuit::wrap_mut_2(fold)).0
}
};
}
(@internal [$($constness:tt)*] $fold:ident -> $try_fold:ident) => {
#[inline]
fn $fold<AAA, FFF>(mut self, init: AAA, fold: FFF) -> AAA
where
Self: $($constness)* Destruct,
FFF: $($constness)* FnMut(AAA, Self::Item) -> AAA
+ $($constness)* Destruct,
{
use crate::ops::NeverShortCircuit;

self.$try_fold(init, NeverShortCircuit::wrap_mut_2(fold)).0
}
};
}

#[unstable(feature = "iter_array_chunks", issue = "100450")]
pub use self::adapters::ArrayChunks;
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{
FusedIterator, TrustedLen, TrustedRandomAccess, TrustedRandomAccessNoCoerce, TrustedStep,
};
use crate::ascii::Char as AsciiChar;
use crate::marker::Destruct;
use crate::mem;
use crate::net::{Ipv4Addr, Ipv6Addr};
use crate::num::NonZero;
Expand Down
Loading