From 6644da5805aa6af93bbe1dcba800d9bdaae56b13 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 9 Jan 2013 17:14:30 -0800 Subject: [PATCH] core: fix crashing vec methods due to non-working moved self. --- src/libcore/vec.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 761b82c0582..f84c1a9f0be 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -413,7 +413,9 @@ pub fn partition(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; - do v.consume |_, elt| { + // FIXME (#4355 maybe): using v.consume here crashes + // do v.consume |_, elt| { + do consume(v) |_, elt| { if f(&elt) { lefts.push(elt); } else { @@ -855,7 +857,9 @@ pub pure fn filter_map(v: &[T], f: fn(t: &T) -> Option) */ pub fn filter(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; - do v.consume |_, elem| { + // FIXME (#4355 maybe): using v.consume here crashes + // do v.consume |_, elem| { + do consume(v) |_, elem| { if f(&elem) { result.push(elem); } } result @@ -3186,10 +3190,11 @@ mod tests { #[test] fn test_partition() { - assert (~[]).partition(|x: &int| *x < 3) == (~[], ~[]); - assert (~[1, 2, 3]).partition(|x: &int| *x < 4) == (~[1, 2, 3], ~[]); - assert (~[1, 2, 3]).partition(|x: &int| *x < 2) == (~[1], ~[2, 3]); - assert (~[1, 2, 3]).partition(|x: &int| *x < 0) == (~[], ~[1, 2, 3]); + // FIXME (#4355 maybe): using v.partition here crashes + assert partition(~[], |x: &int| *x < 3) == (~[], ~[]); + assert partition(~[1, 2, 3], |x: &int| *x < 4) == (~[1, 2, 3], ~[]); + assert partition(~[1, 2, 3], |x: &int| *x < 2) == (~[1], ~[2, 3]); + assert partition(~[1, 2, 3], |x: &int| *x < 0) == (~[], ~[1, 2, 3]); } #[test]