Skip to content

Commit 133d451

Browse files
committed
auto merge of #6886 : jld/rust/vec-each-ret-fix, r=sanxiyn
2 parents af418f2 + c5d7a77 commit 133d451

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
@@ -1564,7 +1564,7 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
15641564
}
15651565
broke = n > 0;
15661566
}
1567-
return true;
1567+
return !broke;
15681568
}
15691569

15701570
/// 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 {
15861586
}
15871587
broke = n > 0;
15881588
}
1589-
return broke;
1589+
return !broke;
15901590
}
15911591

15921592
/// Like `each()`, but for the case where you have a vector that *may or may
@@ -3598,6 +3598,23 @@ mod tests {
35983598
}
35993599
}
36003600

3601+
#[test]
3602+
fn test_each_ret_len0() {
3603+
let mut a0 : [int, .. 0] = [];
3604+
assert_eq!(each(a0, |_p| fail!()), true);
3605+
assert_eq!(each_mut(a0, |_p| fail!()), true);
3606+
}
3607+
3608+
#[test]
3609+
fn test_each_ret_len1() {
3610+
let mut a1 = [17];
3611+
assert_eq!(each(a1, |_p| true), true);
3612+
assert_eq!(each_mut(a1, |_p| true), true);
3613+
assert_eq!(each(a1, |_p| false), false);
3614+
assert_eq!(each_mut(a1, |_p| false), false);
3615+
}
3616+
3617+
36013618
#[test]
36023619
fn test_each_permutation() {
36033620
let mut results: ~[~[int]];

0 commit comments

Comments
 (0)