Auto merge of #56904 - sinkuu:cycle_fold, r=bluss
Remove Cycle::try_fold override Fixes #56883
This commit is contained in:
commit
adbfec229c
@ -649,19 +649,6 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
|
||||
_ => (usize::MAX, None)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn try_fold<Acc, F, R>(&mut self, init: Acc, mut f: F) -> R where
|
||||
Self: Sized, F: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
|
||||
{
|
||||
let mut accum = init;
|
||||
while let Some(x) = self.iter.next() {
|
||||
accum = f(accum, x)?;
|
||||
accum = self.iter.try_fold(accum, &mut f)?;
|
||||
self.iter = self.orig.clone();
|
||||
}
|
||||
Try::from_ok(accum)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "fused", since = "1.26.0")]
|
||||
|
@ -1003,6 +1003,8 @@ fn test_cycle() {
|
||||
assert_eq!(it.next(), None);
|
||||
|
||||
assert_eq!(empty::<i32>().cycle().fold(0, |acc, x| acc + x), 0);
|
||||
|
||||
assert_eq!(once(1).cycle().skip(1).take(4).fold(0, |acc, x| acc + x), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user