about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-03 18:55:29 -0700
committerbors <bors@rust-lang.org>2013-06-03 18:55:29 -0700
commit133d45171564c8b7de14523c9f3aa87140b9f043 (patch)
tree9273bd92ac8c76c33f2e2e7d00939c1d82888198 /src/libstd
parentaf418f2fd5f9dbebbc786550df97658ec3bf0c65 (diff)
parentc5d7a77a533d33a4681f629744f0d0695c5e08b7 (diff)
downloadrust-133d45171564c8b7de14523c9f3aa87140b9f043.tar.gz
rust-133d45171564c8b7de14523c9f3aa87140b9f043.zip
auto merge of #6886 : jld/rust/vec-each-ret-fix, r=sanxiyn
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/vec.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 255dc1c95f7..9aeee4ba7b7 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -1564,7 +1564,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
@@ -1586,7 +1586,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
@@ -3599,6 +3599,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]];