From c5d7a77a533d33a4681f629744f0d0695c5e08b7 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Sat, 1 Jun 2013 02:35:42 -0700 Subject: [PATCH] Fix vec::each* return values --- src/libstd/vec.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 8eedb70b3a6f4..8cd345c09bbd7 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1532,7 +1532,7 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool { } broke = n > 0; } - return true; + return !broke; } /// Like `each()`, but for the case where you have @@ -1554,7 +1554,7 @@ pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool { } broke = n > 0; } - return broke; + return !broke; } /// Like `each()`, but for the case where you have a vector that *may or may @@ -3566,6 +3566,23 @@ mod tests { } } + #[test] + fn test_each_ret_len0() { + let mut a0 : [int, .. 0] = []; + assert_eq!(each(a0, |_p| fail!()), true); + assert_eq!(each_mut(a0, |_p| fail!()), true); + } + + #[test] + fn test_each_ret_len1() { + let mut a1 = [17]; + assert_eq!(each(a1, |_p| true), true); + assert_eq!(each_mut(a1, |_p| true), true); + assert_eq!(each(a1, |_p| false), false); + assert_eq!(each_mut(a1, |_p| false), false); + } + + #[test] fn test_each_permutation() { let mut results: ~[~[int]];