Skip to content

Commit c5d7a77

Browse files
committed
Fix vec::each* return values
1 parent 44af506 commit c5d7a77

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/libstd/vec.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
15321532
}
15331533
broke = n > 0;
15341534
}
1535-
return true;
1535+
return !broke;
15361536
}
15371537

15381538
/// 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 {
15541554
}
15551555
broke = n > 0;
15561556
}
1557-
return broke;
1557+
return !broke;
15581558
}
15591559

15601560
/// Like `each()`, but for the case where you have a vector that *may or may
@@ -3566,6 +3566,23 @@ mod tests {
35663566
}
35673567
}
35683568

3569+
#[test]
3570+
fn test_each_ret_len0() {
3571+
let mut a0 : [int, .. 0] = [];
3572+
assert_eq!(each(a0, |_p| fail!()), true);
3573+
assert_eq!(each_mut(a0, |_p| fail!()), true);
3574+
}
3575+
3576+
#[test]
3577+
fn test_each_ret_len1() {
3578+
let mut a1 = [17];
3579+
assert_eq!(each(a1, |_p| true), true);
3580+
assert_eq!(each_mut(a1, |_p| true), true);
3581+
assert_eq!(each(a1, |_p| false), false);
3582+
assert_eq!(each_mut(a1, |_p| false), false);
3583+
}
3584+
3585+
35693586
#[test]
35703587
fn test_each_permutation() {
35713588
let mut results: ~[~[int]];

0 commit comments

Comments
 (0)