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: 0 additions & 10 deletions library/alloc/src/collections/vec_deque/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,6 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
.try_fold(init, &mut f)
}

#[inline]
fn fold<B, F>(mut self, init: B, mut f: F) -> B
where
F: FnMut(B, Self::Item) -> B,
{
match self.try_fold(init, |b, item| Ok::<B, !>(f(b, item))) {
Ok(b) => b,
}
}

#[inline]
fn last(mut self) -> Option<Self::Item> {
self.inner.pop_back()
Expand Down
10 changes: 3 additions & 7 deletions library/core/src/iter/traits/double_ended.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};
use crate::ops::{ControlFlow, NeverShortCircuit, Try};

/// An iterator able to yield elements from both ends.
///
Expand Down Expand Up @@ -298,16 +298,12 @@ pub trait DoubleEndedIterator: Iterator {
#[doc(alias = "foldr")]
#[inline]
#[stable(feature = "iter_rfold", since = "1.27.0")]
fn rfold<B, F>(mut self, init: B, mut f: F) -> B
fn rfold<B, F>(mut self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
let mut accum = init;
while let Some(x) = self.next_back() {
accum = f(accum, x);
}
accum
self.try_rfold(init, NeverShortCircuit::wrap_mut_2(f)).0
}

/// Searches for an element of an iterator from the back that satisfies a predicate.
Expand Down
10 changes: 3 additions & 7 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::super::{
use crate::array;
use crate::cmp::{self, Ordering};
use crate::num::NonZero;
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try};
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, NeverShortCircuit, Residual, Try};

fn _assert_is_dyn_compatible(_: &dyn Iterator<Item = ()>) {}

Expand Down Expand Up @@ -2550,16 +2550,12 @@ pub trait Iterator {
#[doc(alias = "inject", alias = "foldl")]
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn fold<B, F>(mut self, init: B, mut f: F) -> B
fn fold<B, F>(mut self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
let mut accum = init;
while let Some(x) = self.next() {
accum = f(accum, x);
}
accum
self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0
}

/// Reduces the elements to a single one, by repeatedly applying a reducing
Expand Down
Loading