about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-07-31 21:07:44 +0200
committerblake2-ppc <blake2-ppc>2013-08-01 16:54:22 +0200
commitdbcb74e247b892a5174524bbbafbe93c51c53f65 (patch)
treedf2939f4665d120716e47f586bd0692eaf68f6c4
parentb18bd785ec489c5c0ae9f84e8144a37e414cdee5 (diff)
downloadrust-dbcb74e247b892a5174524bbbafbe93c51c53f65.tar.gz
rust-dbcb74e247b892a5174524bbbafbe93c51c53f65.zip
extra: Replace `for` with `do { .. }` expr where internal iterators are used
-rw-r--r--src/libextra/arena.rs5
-rw-r--r--src/libextra/bitv.rs45
-rw-r--r--src/libextra/getopts.rs7
-rw-r--r--src/libextra/list.rs9
-rw-r--r--src/libextra/treemap.rs17
5 files changed, 47 insertions, 36 deletions
diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs
index efe1d47563e..31acb5bd498 100644
--- a/src/libextra/arena.rs
+++ b/src/libextra/arena.rs
@@ -72,11 +72,12 @@ impl Drop for Arena {
     fn drop(&self) {
         unsafe {
             destroy_chunk(&self.head);
-            for self.chunks.each |chunk| {
+            do self.chunks.each |chunk| {
                 if !chunk.is_pod {
                     destroy_chunk(chunk);
                 }
-            }
+                true
+            };
         }
     }
 }
diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs
index 4d2d5635eff..c2ea2dee82c 100644
--- a/src/libextra/bitv.rs
+++ b/src/libextra/bitv.rs
@@ -646,9 +646,10 @@ impl BitvSet {
     /// Creates a new bit vector set from the given bit vector
     pub fn from_bitv(bitv: Bitv) -> BitvSet {
         let mut size = 0;
-        for bitv.ones |_| {
+        do bitv.ones |_| {
             size += 1;
-        }
+            true
+        };
         let Bitv{rep, _} = bitv;
         match rep {
             Big(b) => BitvSet{ size: size, bitv: b },
@@ -1354,18 +1355,18 @@ mod tests {
     fn test_small_clear() {
         let mut b = Bitv::new(14, true);
         b.clear();
-        for b.ones |i| {
-            fail!("found 1 at %?", i);
-        }
+        do b.ones |i| {
+            fail!("found 1 at %?", i)
+        };
     }
 
     #[test]
     fn test_big_clear() {
         let mut b = Bitv::new(140, true);
         b.clear();
-        for b.ones |i| {
-            fail!("found 1 at %?", i);
-        }
+        do b.ones |i| {
+            fail!("found 1 at %?", i)
+        };
     }
 
     #[test]
@@ -1400,10 +1401,11 @@ mod tests {
 
         let mut i = 0;
         let expected = [3, 5, 11, 77];
-        for a.intersection(&b) |x| {
+        do a.intersection(&b) |x| {
             assert_eq!(*x, expected[i]);
-            i += 1
-        }
+            i += 1;
+            true
+        };
         assert_eq!(i, expected.len());
     }
 
@@ -1423,10 +1425,11 @@ mod tests {
 
         let mut i = 0;
         let expected = [1, 5, 500];
-        for a.difference(&b) |x| {
+        do a.difference(&b) |x| {
             assert_eq!(*x, expected[i]);
-            i += 1
-        }
+            i += 1;
+            true
+        };
         assert_eq!(i, expected.len());
     }
 
@@ -1448,10 +1451,11 @@ mod tests {
 
         let mut i = 0;
         let expected = [1, 5, 11, 14, 220];
-        for a.symmetric_difference(&b) |x| {
+        do a.symmetric_difference(&b) |x| {
             assert_eq!(*x, expected[i]);
-            i += 1
-        }
+            i += 1;
+            true
+        };
         assert_eq!(i, expected.len());
     }
 
@@ -1476,10 +1480,11 @@ mod tests {
 
         let mut i = 0;
         let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
-        for a.union(&b) |x| {
+        do a.union(&b) |x| {
             assert_eq!(*x, expected[i]);
-            i += 1
-        }
+            i += 1;
+            true
+        };
         assert_eq!(i, expected.len());
     }
 
diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs
index b0e6f82322b..e50693236fd 100644
--- a/src/libextra/getopts.rs
+++ b/src/libextra/getopts.rs
@@ -678,9 +678,10 @@ pub mod groups {
 
             // FIXME: #5516
             let mut desc_rows = ~[];
-            for each_split_within(desc_normalized_whitespace, 54) |substr| {
+            do each_split_within(desc_normalized_whitespace, 54) |substr| {
                 desc_rows.push(substr.to_owned());
-            }
+                true
+            };
 
             // FIXME: #5516
             // wrapped description
@@ -780,7 +781,7 @@ pub mod groups {
     priv fn test_split_within() {
         fn t(s: &str, i: uint, u: &[~str]) {
             let mut v = ~[];
-            for each_split_within(s, i) |s| { v.push(s.to_owned()) }
+            do each_split_within(s, i) |s| { v.push(s.to_owned()); true };
             assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         t("", 0, []);
diff --git a/src/libextra/list.rs b/src/libextra/list.rs
index 8f7ade7228b..0e8c50ac873 100644
--- a/src/libextra/list.rs
+++ b/src/libextra/list.rs
@@ -70,10 +70,11 @@ pub fn find<T:Clone>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> {
 
 /// Returns true if a list contains an element with the given value
 pub fn has<T:Eq>(ls: @List<T>, elt: T) -> bool {
-    for each(ls) |e| {
-        if *e == elt { return true; }
-    }
-    return false;
+    let mut found = false;
+    do each(ls) |e| {
+        if *e == elt { found = true; false } else { true }
+    };
+    return found;
 }
 
 /// Returns true if the list is empty
diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs
index 50ad5c77fba..4e66870a947 100644
--- a/src/libextra/treemap.rs
+++ b/src/libextra/treemap.rs
@@ -1001,11 +1001,12 @@ mod test_treemap {
         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]
@@ -1277,10 +1278,11 @@ mod test_set {
         assert!(m.insert(1));
 
         let mut n = 4;
-        for m.each_reverse |x| {
+        do m.each_reverse |x| {
             assert_eq!(*x, n);
-            n -= 1
-        }
+            n -= 1;
+            true
+        };
     }
 
     fn check(a: &[int], b: &[int], expected: &[int],
@@ -1292,10 +1294,11 @@ mod test_set {
         foreach y in b.iter() { assert!(set_b.insert(*y)) }
 
         let mut i = 0;
-        for f(&set_a, &set_b) |x| {
+        do f(&set_a, &set_b) |x| {
             assert_eq!(*x, expected[i]);
             i += 1;
-        }
+            true
+        };
         assert_eq!(i, expected.len());
     }