diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-08-03 00:07:20 -0700 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-08-03 00:07:20 -0700 |
| commit | deddb009f0003734d3c73fa859826d57ec600270 (patch) | |
| tree | 3646e0cc53c8b1203e8b16d6efc21e4b46c52be3 /src/libstd | |
| parent | 2a7be1c9e4d5a50dab4f3f95c8f1d843a7d6f084 (diff) | |
| parent | 87cf2864b1e427753f3153ee31aafcff19e253ca (diff) | |
| download | rust-deddb009f0003734d3c73fa859826d57ec600270.tar.gz rust-deddb009f0003734d3c73fa859826d57ec600270.zip | |
Merge pull request #8244 from thestinger/for
make `for` parse as `foreach` does r=huonw, bors is acting up and this has been run through the try bots
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/char.rs | 5 | ||||
| -rw-r--r-- | src/libstd/cmp.rs | 4 | ||||
| -rw-r--r-- | src/libstd/num/int_macros.rs | 49 | ||||
| -rw-r--r-- | src/libstd/num/uint_macros.rs | 51 | ||||
| -rw-r--r-- | src/libstd/rand.rs | 15 | ||||
| -rw-r--r-- | src/libstd/run.rs | 5 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 39 |
7 files changed, 97 insertions, 71 deletions
diff --git a/src/libstd/char.rs b/src/libstd/char.rs index 47473c2faba..85053855432 100644 --- a/src/libstd/char.rs +++ b/src/libstd/char.rs @@ -211,12 +211,13 @@ pub fn escape_unicode(c: char, f: &fn(char)) { (c <= '\uffff') { f('u'); 4 } _ { f('U'); 8 } ); - for int::range_step(4 * (pad - 1), -1, -4) |offset| { + do int::range_step(4 * (pad - 1), -1, -4) |offset| { match ((c as u32) >> offset) & 0xf { i @ 0 .. 9 => { f('0' + i as char); } i => { f('a' + (i - 10) as char); } } - } + true + }; } /// diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs index 7991e1cb56e..abb04e637ca 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -236,7 +236,9 @@ mod test { fn t(o1: Ordering, o2: Ordering, e: Ordering) { assert_eq!(lexical_ordering(o1, o2), e); } - for [Less, Equal, Greater].each |&o| { + + let xs = [Less, Equal, Greater]; + foreach &o in xs.iter() { t(Less, o, Less); t(Equal, o, o); t(Greater, o, Greater); diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 9aa79090425..9842a570d7e 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -889,27 +889,34 @@ mod tests { fn test_ranges() { let mut l = ~[]; - for range_rev(14,11) |i| { + do range_rev(14,11) |i| { l.push(i); - } - for range_step(20,26,2) |i| { + true + }; + do range_step(20,26,2) |i| { l.push(i); - } - for range_step(36,30,-2) |i| { + true + }; + do range_step(36,30,-2) |i| { l.push(i); - } - for range_step(max_value - 2, max_value, 2) |i| { + true + }; + do range_step(max_value - 2, max_value, 2) |i| { l.push(i); - } - for range_step(max_value - 3, max_value, 2) |i| { + true + }; + do range_step(max_value - 3, max_value, 2) |i| { l.push(i); - } - for range_step(min_value + 2, min_value, -2) |i| { + true + }; + do range_step(min_value + 2, min_value, -2) |i| { l.push(i); - } - for range_step(min_value + 3, min_value, -2) |i| { + true + }; + do range_step(min_value + 3, min_value, -2) |i| { l.push(i); - } + true + }; assert_eq!(l, ~[13,12,11, 20,22,24, 36,34,32, @@ -919,22 +926,22 @@ mod tests { min_value+3,min_value+1]); // None of the `fail`s should execute. - for range_rev(0,10) |_i| { + do range_rev(0,10) |_i| { fail!(~"unreachable"); - } - for range_step(10,0,1) |_i| { + }; + do range_step(10,0,1) |_i| { fail!(~"unreachable"); - } - for range_step(0,10,-1) |_i| { + }; + do range_step(0,10,-1) |_i| { fail!(~"unreachable"); - } + }; } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_range_step_zero_step() { - for range_step(0,10,0) |_i| {} + do range_step(0,10,0) |_i| { true }; } } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index aa01b871b9d..a2874c96703 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -654,27 +654,34 @@ mod tests { pub fn test_ranges() { let mut l = ~[]; - for range_rev(14,11) |i| { + do range_rev(14,11) |i| { l.push(i); - } - for range_step(20,26,2) |i| { + true + }; + do range_step(20,26,2) |i| { l.push(i); - } - for range_step(36,30,-2) |i| { + true + }; + do range_step(36,30,-2) |i| { l.push(i); - } - for range_step(max_value - 2, max_value, 2) |i| { + true + }; + do range_step(max_value - 2, max_value, 2) |i| { l.push(i); - } - for range_step(max_value - 3, max_value, 2) |i| { + true + }; + do range_step(max_value - 3, max_value, 2) |i| { l.push(i); - } - for range_step(min_value + 2, min_value, -2) |i| { + true + }; + do range_step(min_value + 2, min_value, -2) |i| { l.push(i); - } - for range_step(min_value + 3, min_value, -2) |i| { + true + }; + do range_step(min_value + 3, min_value, -2) |i| { l.push(i); - } + true + }; assert_eq!(l, ~[13,12,11, 20,22,24, @@ -685,28 +692,28 @@ mod tests { min_value+3,min_value+1]); // None of the `fail`s should execute. - for range_rev(0,0) |_i| { + do range_rev(0,0) |_i| { fail!("unreachable"); - } - for range_step(10,0,1) |_i| { + }; + do range_step(10,0,1) |_i| { fail!("unreachable"); - } - for range_step(0,1,-10) |_i| { + }; + do range_step(0,1,-10) |_i| { fail!("unreachable"); - } + }; } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_range_step_zero_step_up() { - for range_step(0,10,0) |_i| {} + do range_step(0,10,0) |_i| { true }; } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_range_step_zero_step_down() { - for range_step(0,-10,0) |_i| {} + do range_step(0,-10,0) |_i| { true }; } } diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 20686e7a251..69e1852e662 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -701,7 +701,7 @@ impl IsaacRng { if use_rsl { macro_rules! memloop ( ($arr:expr) => {{ - for u32::range_step(0, RAND_SIZE, 8) |i| { + do u32::range_step(0, RAND_SIZE, 8) |i| { a+=$arr[i ]; b+=$arr[i+1]; c+=$arr[i+2]; d+=$arr[i+3]; e+=$arr[i+4]; f+=$arr[i+5]; @@ -711,20 +711,22 @@ impl IsaacRng { self.mem[i+2]=c; self.mem[i+3]=d; self.mem[i+4]=e; self.mem[i+5]=f; self.mem[i+6]=g; self.mem[i+7]=h; - } + true + }; }} ); memloop!(self.rsl); memloop!(self.mem); } else { - for u32::range_step(0, RAND_SIZE, 8) |i| { + do u32::range_step(0, RAND_SIZE, 8) |i| { mix!(); self.mem[i ]=a; self.mem[i+1]=b; self.mem[i+2]=c; self.mem[i+3]=d; self.mem[i+4]=e; self.mem[i+5]=f; self.mem[i+6]=g; self.mem[i+7]=h; - } + true + }; } self.isaac(); @@ -764,12 +766,13 @@ impl IsaacRng { let r = [(0, MIDPOINT), (MIDPOINT, 0)]; foreach &(mr_offset, m2_offset) in r.iter() { - for uint::range_step(0, MIDPOINT, 4) |base| { + do uint::range_step(0, MIDPOINT, 4) |base| { rngstep!(0, 13); rngstep!(1, -6); rngstep!(2, 2); rngstep!(3, -16); - } + true + }; } self.a = a; diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 65316d4092b..4c67d844c7e 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -665,9 +665,10 @@ fn spawn_process_os(prog: &str, args: &[~str], fail!("failure in dup3(err_fd, 2): %s", os::last_os_error()); } // close all other fds - for int::range_rev(getdtablesize() as int, 3) |fd| { + do int::range_rev(getdtablesize() as int, 3) |fd| { close(fd as c_int); - } + true + }; do with_dirp(dir) |dirp| { if !dirp.is_null() && chdir(dirp) == -1 { diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 97e2b3b3c34..9bcf430ff90 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -272,14 +272,13 @@ impl<T> TrieNode<T> { } fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { - for uint::range_rev(self.children.len(), 0) |idx| { + do uint::range_rev(self.children.len(), 0) |idx| { match self.children[idx] { - Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false }, - External(k, ref v) => if !f(&k, v) { return false }, - Nothing => () + Internal(ref x) => x.each_reverse(|i,t| f(i,t)), + External(k, ref v) => f(&k, v), + Nothing => true } } - true } fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool { @@ -417,17 +416,19 @@ mod test_map { let mut trie = TrieMap::new(); let n = 300; - for uint::range_step(1, n, 2) |x| { + do uint::range_step(1, n, 2) |x| { assert!(trie.insert(x, x + 1)); assert!(trie.contains_key(&x)); check_integrity(&trie.root); - } + true + }; - for uint::range_step(0, n, 2) |x| { + do uint::range_step(0, n, 2) |x| { assert!(!trie.contains_key(&x)); assert!(trie.insert(x, x + 1)); check_integrity(&trie.root); - } + true + }; foreach x in range(0u, n) { assert!(trie.contains_key(&x)); @@ -435,17 +436,19 @@ mod test_map { check_integrity(&trie.root); } - for uint::range_step(1, n, 2) |x| { + do uint::range_step(1, n, 2) |x| { assert!(trie.remove(&x)); assert!(!trie.contains_key(&x)); check_integrity(&trie.root); - } + true + }; - for uint::range_step(0, n, 2) |x| { + do uint::range_step(0, n, 2) |x| { assert!(trie.contains_key(&x)); assert!(!trie.insert(x, x + 1)); check_integrity(&trie.root); - } + true + }; } #[test] @@ -471,9 +474,10 @@ mod test_map { fn test_each_break() { let mut m = TrieMap::new(); - for uint::range_rev(uint::max_value, uint::max_value - 10000) |x| { + do uint::range_rev(uint::max_value, uint::max_value - 10000) |x| { m.insert(x, x / 2); - } + true + }; let mut n = uint::max_value - 10000; do m.each |k, v| { @@ -511,9 +515,10 @@ mod test_map { fn test_each_reverse_break() { let mut m = TrieMap::new(); - for uint::range_rev(uint::max_value, uint::max_value - 10000) |x| { + do uint::range_rev(uint::max_value, uint::max_value - 10000) |x| { m.insert(x, x / 2); - } + true + }; let mut n = uint::max_value - 1; do m.each_reverse |k, v| { |
