Skip to content

Commit 6644da5

Browse files
committed
core: fix crashing vec methods due to non-working moved self.
1 parent 6a2e495 commit 6644da5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/libcore/vec.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ pub fn partition<T>(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) {
413413
let mut lefts = ~[];
414414
let mut rights = ~[];
415415

416-
do v.consume |_, elt| {
416+
// FIXME (#4355 maybe): using v.consume here crashes
417+
// do v.consume |_, elt| {
418+
do consume(v) |_, elt| {
417419
if f(&elt) {
418420
lefts.push(elt);
419421
} else {
@@ -855,7 +857,9 @@ pub pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>)
855857
*/
856858
pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] {
857859
let mut result = ~[];
858-
do v.consume |_, elem| {
860+
// FIXME (#4355 maybe): using v.consume here crashes
861+
// do v.consume |_, elem| {
862+
do consume(v) |_, elem| {
859863
if f(&elem) { result.push(elem); }
860864
}
861865
result
@@ -3186,10 +3190,11 @@ mod tests {
31863190

31873191
#[test]
31883192
fn test_partition() {
3189-
assert (~[]).partition(|x: &int| *x < 3) == (~[], ~[]);
3190-
assert (~[1, 2, 3]).partition(|x: &int| *x < 4) == (~[1, 2, 3], ~[]);
3191-
assert (~[1, 2, 3]).partition(|x: &int| *x < 2) == (~[1], ~[2, 3]);
3192-
assert (~[1, 2, 3]).partition(|x: &int| *x < 0) == (~[], ~[1, 2, 3]);
3193+
// FIXME (#4355 maybe): using v.partition here crashes
3194+
assert partition(~[], |x: &int| *x < 3) == (~[], ~[]);
3195+
assert partition(~[1, 2, 3], |x: &int| *x < 4) == (~[1, 2, 3], ~[]);
3196+
assert partition(~[1, 2, 3], |x: &int| *x < 2) == (~[1], ~[2, 3]);
3197+
assert partition(~[1, 2, 3], |x: &int| *x < 0) == (~[], ~[1, 2, 3]);
31933198
}
31943199

31953200
#[test]

0 commit comments

Comments
 (0)