diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2013-01-09 17:14:30 -0800 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2013-01-09 17:21:21 -0800 |
| commit | 6644da5805aa6af93bbe1dcba800d9bdaae56b13 (patch) | |
| tree | 38b6eddbc4e97731001f72d027d4611a00f5c298 | |
| parent | 6a2e495d673932526676ca6980e0ea8da14725dd (diff) | |
core: fix crashing vec methods due to non-working moved self.
| -rw-r--r-- | src/libcore/vec.rs | 17 |
1 files 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<T>(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<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>) */ pub fn filter<T>(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] |
