Auto merge of #56904 - sinkuu:cycle_fold, r=bluss

Remove Cycle::try_fold override

Fixes #56883
This commit is contained in:
bors 2018-12-17 16:01:46 +00:00
commit adbfec229c
2 changed files with 2 additions and 13 deletions

View File

@ -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")]

View File

@ -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]