Skip to content

Commit

Permalink
Fix vec::each* return values
Browse files Browse the repository at this point in the history
  • Loading branch information
jld committed Jun 1, 2013
1 parent 44af506 commit c5d7a77
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]];
Expand Down

5 comments on commit c5d7a77

@bors
Copy link
Contributor

@bors bors commented on c5d7a77 Jun 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from sanxiyn
at jld@c5d7a77

@bors
Copy link
Contributor

@bors bors commented on c5d7a77 Jun 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jld/rust/vec-each-ret-fix = c5d7a77 into auto

@bors
Copy link
Contributor

@bors bors commented on c5d7a77 Jun 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jld/rust/vec-each-ret-fix = c5d7a77 merged ok, testing candidate = 133d451

@bors
Copy link
Contributor

@bors bors commented on c5d7a77 Jun 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c5d7a77 Jun 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 133d451

Please sign in to comment.