From f0483f76e6feb256abffb060029f57e09c6d4dc0 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Mon, 17 Dec 2018 09:35:28 +0900 Subject: [PATCH] Remove `::try_fold` override It was a incorrect optimization. --- src/libcore/iter/mod.rs | 13 ------------- src/libcore/tests/iter.rs | 2 ++ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 7b273f7862a..aa23d49672a 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -649,19 +649,6 @@ fn size_hint(&self) -> (usize, Option) { _ => (usize::MAX, None) } } - - #[inline] - fn try_fold(&mut self, init: Acc, mut f: F) -> R where - Self: Sized, F: FnMut(Acc, Self::Item) -> R, R: Try - { - 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")] diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 4efa0136314..00b4aa4fa2d 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1003,6 +1003,8 @@ fn test_cycle() { assert_eq!(it.next(), None); assert_eq!(empty::().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]