diff options
| -rw-r--r-- | src/libextra/serialize.rs | 10 | ||||
| -rw-r--r-- | src/libstd/cleanup.rs | 15 | ||||
| -rw-r--r-- | src/libstd/hashmap.rs | 35 | ||||
| -rw-r--r-- | src/libstd/io.rs | 17 | ||||
| -rw-r--r-- | src/libstd/os.rs | 3 | ||||
| -rw-r--r-- | src/libstd/task/spawn.rs | 3 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 51 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 33 | ||||
| -rw-r--r-- | src/test/run-pass/issue-2904.rs | 7 |
9 files changed, 96 insertions, 78 deletions
diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 0c8821e753e..95f3af006e8 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -784,11 +784,12 @@ impl< fn encode(&self, e: &mut E) { do e.emit_map(self.len()) |e| { let mut i = 0; - for self.each |key, val| { + do self.each |key, val| { e.emit_map_elt_key(i, |e| key.encode(e)); e.emit_map_elt_val(i, |e| val.encode(e)); i += 1; - } + true + }; } } } @@ -814,10 +815,11 @@ impl<S: Encoder> Encodable<S> for TrieSet { fn encode(&self, s: &mut S) { do s.emit_seq(self.len()) |s| { let mut i = 0; - for self.each |e| { + do self.each |e| { s.emit_seq_elt(i, |s| e.encode(s)); i += 1; - } + true + }; } } } diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index ed2b0e16818..24ca6fc2309 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -94,27 +94,29 @@ pub unsafe fn annihilate() { // // In this pass, nothing gets freed, so it does not matter whether // we read the next field before or after the callback. - for each_live_alloc(true) |box, uniq| { + do each_live_alloc(true) |box, uniq| { stats.n_total_boxes += 1; if uniq { stats.n_unique_boxes += 1; } else { (*box).ref_count = managed::RC_IMMORTAL; } - } + true + }; // Pass 2: Drop all boxes. // // In this pass, unique-managed boxes may get freed, but not // managed boxes, so we must read the `next` field *after* the // callback, as the original value may have been freed. - for each_live_alloc(false) |box, uniq| { + do each_live_alloc(false) |box, uniq| { if !uniq { let tydesc = (*box).type_desc; let data = &(*box).data as *(); ((*tydesc).drop_glue)(data as *i8); } - } + true + }; // Pass 3: Free all boxes. // @@ -122,14 +124,15 @@ pub unsafe fn annihilate() { // unique-managed boxes, though I think that none of those are // left), so we must read the `next` field before, since it will // not be valid after. - for each_live_alloc(true) |box, uniq| { + do each_live_alloc(true) |box, uniq| { if !uniq { stats.n_bytes_freed += (*((*box).type_desc)).size + sys::size_of::<raw::Box<()>>(); local_free(box as *i8); } - } + true + }; if debug_mem() { // We do logging here w/o allocation. diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index b162869201d..8c06f23b8c1 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -130,15 +130,17 @@ impl<K:Hash + Eq,V> HashMap<K, V> { hash: uint, k: &K) -> SearchResult { - for self.bucket_sequence(hash) |i| { + let mut ret = TableFull; + do self.bucket_sequence(hash) |i| { match self.buckets[i] { - Some(ref bkt) => if bkt.hash == hash && *k == bkt.key { - return FoundEntry(i); + Some(ref bkt) if bkt.hash == hash && *k == bkt.key => { + ret = FoundEntry(i); false }, - None => return FoundHole(i) + None => { ret = FoundHole(i); false } + _ => true, } - } - TableFull + }; + ret } #[inline] @@ -146,17 +148,17 @@ impl<K:Hash + Eq,V> HashMap<K, V> { hash: uint, k: &Q) -> SearchResult { - for self.bucket_sequence(hash) |i| { + let mut ret = TableFull; + do self.bucket_sequence(hash) |i| { match self.buckets[i] { - Some(ref bkt) => { - if bkt.hash == hash && k.equiv(&bkt.key) { - return FoundEntry(i); - } + Some(ref bkt) if bkt.hash == hash && k.equiv(&bkt.key) => { + ret = FoundEntry(i); false }, - None => return FoundHole(i) + None => { ret = FoundHole(i); false } + _ => true, } - } - TableFull + }; + ret } /// Expand the capacity of the array to the next power of two @@ -272,11 +274,6 @@ impl<K:Hash + Eq,V> HashMap<K, V> { value } - - fn search(&self, hash: uint, - op: &fn(x: &Option<Bucket<K, V>>) -> bool) { - let _ = self.bucket_sequence(hash, |i| op(&self.buckets[i])); - } } impl<K:Hash + Eq,V> Container for HashMap<K, V> { diff --git a/src/libstd/io.rs b/src/libstd/io.rs index cef183d0429..153286a311a 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -770,9 +770,10 @@ impl<T:Reader> ReaderUtil for T { fn read_lines(&self) -> ~[~str] { do vec::build |push| { - for self.each_line |line| { + do self.each_line |line| { push(line.to_owned()); - } + true + }; } } @@ -1880,16 +1881,16 @@ mod tests { { let file = io::file_reader(&path).unwrap(); - for file.each_byte() |_| { - fail!("must be empty"); - } + do file.each_byte() |_| { + fail!("must be empty") + }; } { let file = io::file_reader(&path).unwrap(); - for file.each_char() |_| { - fail!("must be empty"); - } + do file.each_char() |_| { + fail!("must be empty") + }; } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 3afd946ee26..1bfae8c40e1 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -790,7 +790,7 @@ pub fn list_dir_path(p: &Path) -> ~[Path] { /// all its contents. Use carefully! pub fn remove_dir_recursive(p: &Path) -> bool { let mut error_happened = false; - for walk_dir(p) |inner| { + do walk_dir(p) |inner| { if !error_happened { if path_is_dir(inner) { if !remove_dir_recursive(inner) { @@ -803,6 +803,7 @@ pub fn remove_dir_recursive(p: &Path) -> bool { } } } + true }; // Directory should now be empty !error_happened && remove_dir(p) diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 81db5e690a6..4558f8e32c1 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -372,8 +372,9 @@ impl Drop for Taskgroup { // with our own taskgroup, so long as both happen before we die. // We remove ourself from every ancestor we can, so no cleanup; no // break. - for each_ancestor(&mut this.ancestors, |_| {}) |ancestor_group| { + do each_ancestor(&mut this.ancestors, |_| {}) |ancestor_group| { leave_taskgroup(ancestor_group, &me, false); + true }; } } diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index 704e3a500f1..f60093ce48c 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -459,11 +459,12 @@ mod test_map { assert!(m.insert(1, 2)); let mut n = 0; - for m.each |k, v| { + do m.each |k, v| { assert_eq!(*k, n); assert_eq!(*v, n * 2); n += 1; - } + true + }; } #[test] @@ -475,14 +476,16 @@ mod test_map { } let mut n = uint::max_value - 10000; - for m.each |k, v| { - if n == uint::max_value - 5000 { break } - assert!(n < uint::max_value - 5000); - - assert_eq!(*k, n); - assert_eq!(*v, n / 2); - n += 1; - } + do m.each |k, v| { + if n == uint::max_value - 5000 { false } else { + assert!(n < uint::max_value - 5000); + + assert_eq!(*k, n); + assert_eq!(*v, n / 2); + n += 1; + true + } + }; } #[test] @@ -496,11 +499,12 @@ mod test_map { assert!(m.insert(1, 2)); let mut n = 4; - for m.each_reverse |k, v| { + do m.each_reverse |k, v| { assert_eq!(*k, n); assert_eq!(*v, n * 2); n -= 1; - } + true + }; } #[test] @@ -512,14 +516,16 @@ mod test_map { } let mut n = uint::max_value - 1; - for m.each_reverse |k, v| { - if n == uint::max_value - 5000 { break } - assert!(n > uint::max_value - 5000); - - assert_eq!(*k, n); - assert_eq!(*v, n / 2); - n -= 1; - } + do m.each_reverse |k, v| { + if n == uint::max_value - 5000 { false } else { + assert!(n > uint::max_value - 5000); + + assert_eq!(*k, n); + assert_eq!(*v, n / 2); + n -= 1; + true + } + }; } #[test] @@ -572,10 +578,11 @@ mod test_set { let mut i = 0; - for trie.each |x| { + do trie.each |x| { assert_eq!(expected[i], *x); i += 1; - } + true + }; } #[test] diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 534dc27196c..6cff9ce84cf 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2767,19 +2767,19 @@ mod tests { let mut results: ~[~[int]]; results = ~[]; - for each_permutation([]) |v| { results.push(v.to_owned()); } + do each_permutation([]) |v| { results.push(v.to_owned()); true }; assert_eq!(results, ~[~[]]); results = ~[]; - for each_permutation([7]) |v| { results.push(v.to_owned()); } + do each_permutation([7]) |v| { results.push(v.to_owned()); true }; assert_eq!(results, ~[~[7]]); results = ~[]; - for each_permutation([1,1]) |v| { results.push(v.to_owned()); } + do each_permutation([1,1]) |v| { results.push(v.to_owned()); true }; assert_eq!(results, ~[~[1,1],~[1,1]]); results = ~[]; - for each_permutation([5,2,0]) |v| { results.push(v.to_owned()); } + do each_permutation([5,2,0]) |v| { results.push(v.to_owned()); true }; assert!(results == ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]); } @@ -3107,12 +3107,13 @@ mod tests { fn test_permute_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; - for each_permutation(v) |_elt| { + do each_permutation(v) |_elt| { if i == 2 { fail!() } i += 0; - } + true + }; } #[test] @@ -3425,9 +3426,10 @@ mod tests { fn test_permutations0() { let values = []; let mut v : ~[~[int]] = ~[]; - for each_permutation(values) |p| { + do each_permutation(values) |p| { v.push(p.to_owned()); - } + true + }; assert_eq!(v, ~[~[]]); } @@ -3435,9 +3437,10 @@ mod tests { fn test_permutations1() { let values = [1]; let mut v : ~[~[int]] = ~[]; - for each_permutation(values) |p| { + do each_permutation(values) |p| { v.push(p.to_owned()); - } + true + }; assert_eq!(v, ~[~[1]]); } @@ -3445,9 +3448,10 @@ mod tests { fn test_permutations2() { let values = [1,2]; let mut v : ~[~[int]] = ~[]; - for each_permutation(values) |p| { + do each_permutation(values) |p| { v.push(p.to_owned()); - } + true + }; assert_eq!(v, ~[~[1,2],~[2,1]]); } @@ -3455,9 +3459,10 @@ mod tests { fn test_permutations3() { let values = [1,2,3]; let mut v : ~[~[int]] = ~[]; - for each_permutation(values) |p| { + do each_permutation(values) |p| { v.push(p.to_owned()); - } + true + }; assert_eq!(v, ~[~[1,2,3],~[1,3,2],~[2,1,3],~[2,3,1],~[3,1,2],~[3,2,1]]); } diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 092d5e5813b..b86ad6d56f8 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -65,13 +65,14 @@ fn square_from_char(c: char) -> square { fn read_board_grid<rdr:'static + io::Reader>(input: rdr) -> ~[~[square]] { let input = @input as @io::Reader; let mut grid = ~[]; - for input.each_line |line| { + do input.each_line |line| { let mut row = ~[]; foreach c in line.iter() { row.push(square_from_char(c)) } - grid.push(row) - } + grid.push(row); + true + }; let width = grid[0].len(); foreach row in grid.iter() { assert!(row.len() == width) } grid |
