diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-02-04 23:48:40 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2018-02-04 23:48:40 -0800 |
| commit | 1b1e887f4d40e5800a8d5ae81f8574806e7ba21a (patch) | |
| tree | 3ecc366222ea48517be24d4949ead79116800698 /src/libcore/tests | |
| parent | b8f2674ea47f4f3cf5d90d0428bf8b8025d7f8d8 (diff) | |
Override try_[r]fold for RangeInclusive
Because the last item needs special handling, it seems that LLVM has trouble canonicalizing the loops in external iteration. With the override, it becomes obvious that the start==end case exits the loop (as opposed to the one *after* that exiting the loop in external iteration).
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/iter.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 8997cf9c6bf..e33a0b6224e 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1398,6 +1398,26 @@ fn test_range_inclusive_min() { } #[test] +fn test_range_inclusive_folds() { + assert_eq!((1..=10).sum::<i32>(), 55); + assert_eq!((1..=10).rev().sum::<i32>(), 55); + + let mut it = 40..=50; + assert_eq!(it.try_fold(0, i8::checked_add), None); + assert_eq!(it, 44..=50); + assert_eq!(it.try_rfold(0, i8::checked_add), None); + assert_eq!(it, 44..=47); + + let mut it = 10..=20; + assert_eq!(it.try_fold(0, |a,b| Some(a+b)), Some(165)); + assert_eq!(it, 1..=0); + + let mut it = 10..=20; + assert_eq!(it.try_rfold(0, |a,b| Some(a+b)), Some(165)); + assert_eq!(it, 1..=0); +} + +#[test] fn test_repeat() { let mut it = repeat(42); assert_eq!(it.next(), Some(42)); |
