diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-09-18 21:41:37 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-09-19 10:52:59 -0700 |
| commit | 9cf271fe96b474d514b1052935db70c4056cf076 (patch) | |
| tree | 7a6fb31efeaa4de91317c16aca824153aaaf988c /src/test/run-pass | |
| parent | 62b7f4d800325b46002c47d23b58a9f2b7fabb9b (diff) | |
| download | rust-9cf271fe96b474d514b1052935db70c4056cf076.tar.gz rust-9cf271fe96b474d514b1052935db70c4056cf076.zip | |
De-mode vec::each() and many of the str iteration routines
Note that the method foo.each() is not de-moded, nor the other vec routines.
Diffstat (limited to 'src/test/run-pass')
| -rw-r--r-- | src/test/run-pass/assignability-trait.rs | 20 | ||||
| -rw-r--r-- | src/test/run-pass/auto-loop.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/block-arg.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/break.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/rcvr-borrowed-to-slice.rs | 2 |
6 files changed, 21 insertions, 17 deletions
diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 37c7f36445c..4652212ce5f 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -2,21 +2,23 @@ // making method calls, but only if there aren't any matches without // it. -#[legacy_modes]; - trait iterable<A> { - fn iterate(blk: fn(A) -> bool); + fn iterate(blk: fn(x: &A) -> bool); } impl<A> &[A]: iterable<A> { - fn iterate(f: fn(A) -> bool) { - vec::each(self, f); + fn iterate(f: fn(x: &A) -> bool) { + for vec::each(self) |e| { + if !f(e) { break; } + } } } impl<A> ~[A]: iterable<A> { - fn iterate(f: fn(A) -> bool) { - vec::each(self, f); + fn iterate(f: fn(x: &A) -> bool) { + for vec::each(self) |e| { + if !f(e) { break; } + } } } @@ -29,7 +31,7 @@ fn length<A, T: iterable<A>>(x: T) -> uint { fn main() { let x = ~[0,1,2,3]; // Call a method - for x.iterate() |y| { assert x[y] == y; } + for x.iterate() |y| { assert x[*y] == *y; } // Call a parameterized function assert length(x) == vec::len(x); // Call a parameterized function, with type arguments that require @@ -39,7 +41,7 @@ fn main() { // Now try it with a type that *needs* to be borrowed let z = [0,1,2,3]/_; // Call a method - for z.iterate() |y| { assert z[y] == y; } + for z.iterate() |y| { assert z[*y] == *y; } // Call a parameterized function assert length::<int, &[int]>(z) == vec::len(z); } diff --git a/src/test/run-pass/auto-loop.rs b/src/test/run-pass/auto-loop.rs index f33f0b3bc8f..aaea21c7e82 100644 --- a/src/test/run-pass/auto-loop.rs +++ b/src/test/run-pass/auto-loop.rs @@ -1,5 +1,7 @@ fn main() { let mut sum = 0; - for vec::each(~[1, 2, 3, 4, 5]) |x| { sum += x; } + for vec::each(~[1, 2, 3, 4, 5]) |x| { + sum += *x; + } assert (sum == 15); } diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index db941d32e11..6110fe9c388 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -3,8 +3,8 @@ fn main() { let v = ~[-1f, 0f, 1f, 2f, 3f]; // Statement form does not require parentheses: - do vec::iter(v) |i| { - log(info, i); + for vec::each(v) |i| { + log(info, *i); } // Usable at all: diff --git a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs index b96a40dc088..26d8d6bbb73 100644 --- a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs +++ b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs @@ -1,6 +1,6 @@ fn want_slice(v: &[int]) -> int { let mut sum = 0; - for vec::each(v) |i| { sum += i; } + for vec::each(v) |i| { sum += *i; } return sum; } diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs index 1b7a3a24649..57e72b43c0d 100644 --- a/src/test/run-pass/break.rs +++ b/src/test/run-pass/break.rs @@ -7,7 +7,7 @@ fn main() { loop { i += 1; if i == 20 { break; } } assert (i == 20); for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { - if x == 3 { break; } assert (x <= 3); + if *x == 3 { break; } assert (*x <= 3); } i = 0; while i < 10 { i += 1; if i % 2 == 0 { loop; } assert (i % 2 != 0); } @@ -17,7 +17,7 @@ fn main() { if i >= 10 { break; } } for vec::each(~[1, 2, 3, 4, 5, 6]) |x| { - if x % 2 == 0 { loop; } - assert (x % 2 != 0); + if *x % 2 == 0 { loop; } + assert (*x % 2 != 0); } } diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index 8ac43d72baf..84dabf56133 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -6,7 +6,7 @@ trait sum { impl &[int]: sum { fn sum() -> int { let mut sum = 0; - for vec::each(self) |e| { sum += e; } + for vec::each(self) |e| { sum += *e; } return sum; } } |
