about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-08-01 04:18:19 +0200
committerblake2-ppc <blake2-ppc>2013-08-01 16:54:22 +0200
commit78cde5b9fb9db91f954f7fe4afdd230de6754e54 (patch)
tree524e26fcde0b5f86f453eac7768b4881d6f979fc /src/libstd
parent7e210a8129c844e0b3aca4a28153effd0817ef41 (diff)
downloadrust-78cde5b9fb9db91f954f7fe4afdd230de6754e54.tar.gz
rust-78cde5b9fb9db91f954f7fe4afdd230de6754e54.zip
std: Change `Times` trait to use `do` instead of `for`
Change the former repetition::

    for 5.times { }

to::

    do 5.times { }

.times() cannot be broken with `break` or `return` anymore; for those
cases, use a numerical range loop instead.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/iter.rs4
-rw-r--r--src/libstd/iterator.rs6
-rw-r--r--src/libstd/num/uint.rs13
-rw-r--r--src/libstd/rand.rs6
-rw-r--r--src/libstd/rt/comm.rs38
-rw-r--r--src/libstd/rt/io/net/tcp.rs8
-rw-r--r--src/libstd/rt/mod.rs2
-rw-r--r--src/libstd/rt/sched.rs2
-rw-r--r--src/libstd/rt/select.rs4
-rw-r--r--src/libstd/str.rs2
-rw-r--r--src/libstd/task/mod.rs18
-rw-r--r--src/libstd/unstable/extfmt.rs2
-rw-r--r--src/libstd/unstable/sync.rs2
13 files changed, 53 insertions, 54 deletions
diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs
index 2092ae588d0..ce528bc9522 100644
--- a/src/libstd/iter.rs
+++ b/src/libstd/iter.rs
@@ -14,13 +14,13 @@
 use iter::Times;
 let ten = 10 as uint;
 let mut accum = 0;
-for ten.times { accum += 1; }
+do ten.times { accum += 1; }
 ~~~
 
 */
 
 #[allow(missing_doc)]
 pub trait Times {
-    fn times(&self, it: &fn() -> bool) -> bool;
+    fn times(&self, it: &fn());
 }
 
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs
index 84923876cbf..013901d57f8 100644
--- a/src/libstd/iterator.rs
+++ b/src/libstd/iterator.rs
@@ -18,7 +18,6 @@ implementing the `Iterator` trait.
 */
 
 use cmp;
-use iter::Times;
 use num::{Zero, One};
 use option::{Option, Some, None};
 use ops::{Add, Mul};
@@ -1229,8 +1228,9 @@ impl<A, T: Iterator<A>> Iterator<A> for Skip<T> {
         if self.n == 0 {
             next
         } else {
-            let n = self.n;
-            for n.times {
+            let mut n = self.n;
+            while n > 0 {
+                n -= 1;
                 match next {
                     Some(_) => {
                         next = self.iter.next();
diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs
index 126150c0f1b..275a72d6ecc 100644
--- a/src/libstd/num/uint.rs
+++ b/src/libstd/num/uint.rs
@@ -97,22 +97,21 @@ pub fn iterate(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
 impl iter::Times for uint {
     #[inline]
     ///
-    /// A convenience form for basic iteration. Given a uint `x`,
-    /// `for x.times { ... }` executes the given block x times.
+    /// A convenience form for basic repetition. Given a uint `x`,
+    /// `do x.times { ... }` executes the given block x times.
     ///
     /// Equivalent to `for uint::range(0, x) |_| { ... }`.
     ///
     /// Not defined on all integer types to permit unambiguous
     /// use with integer literals of inferred integer-type as
-    /// the self-value (eg. `for 100.times { ... }`).
+    /// the self-value (eg. `do 100.times { ... }`).
     ///
-    fn times(&self, it: &fn() -> bool) -> bool {
+    fn times(&self, it: &fn()) {
         let mut i = *self;
         while i > 0 {
-            if !it() { return false; }
+            it();
             i -= 1;
         }
-        return true;
     }
 }
 
@@ -190,6 +189,6 @@ pub fn test_times() {
     use iter::Times;
     let ten = 10 as uint;
     let mut accum = 0;
-    for ten.times { accum += 1; }
+    do ten.times { accum += 1; }
     assert!((accum == 10));
 }
diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs
index aed68f47fdf..9134d2da257 100644
--- a/src/libstd/rand.rs
+++ b/src/libstd/rand.rs
@@ -695,7 +695,7 @@ impl IsaacRng {
             }}
         );
 
-        for 4.times { mix!(); }
+        do 4.times { mix!(); }
 
         if use_rsl {
             macro_rules! memloop (
@@ -1092,7 +1092,7 @@ mod test {
         }
 
         // run against several seeds
-        for 10.times {
+        do 10.times {
             unsafe {
                 let seed = super::seed();
                 let rt_rng = do seed.as_imm_buf |p, sz| {
@@ -1100,7 +1100,7 @@ mod test {
                 };
                 let mut rng = IsaacRng::new_seeded(seed);
 
-                for 10000.times {
+                do 10000.times {
                     assert_eq!(rng.next(), rustrt::rand_next(rt_rng));
                 }
                 rustrt::rand_free(rt_rng);
diff --git a/src/libstd/rt/comm.rs b/src/libstd/rt/comm.rs
index a27ff559b2b..79ee8405531 100644
--- a/src/libstd/rt/comm.rs
+++ b/src/libstd/rt/comm.rs
@@ -769,7 +769,7 @@ mod test {
 
     #[test]
     fn oneshot_multi_thread_close_stress() {
-        for stress_factor().times {
+        do stress_factor().times {
             do run_in_newsched_task {
                 let (port, chan) = oneshot::<int>();
                 let port_cell = Cell::new(port);
@@ -784,7 +784,7 @@ mod test {
 
     #[test]
     fn oneshot_multi_thread_send_close_stress() {
-        for stress_factor().times {
+        do stress_factor().times {
             do run_in_newsched_task {
                 let (port, chan) = oneshot::<int>();
                 let chan_cell = Cell::new(chan);
@@ -804,7 +804,7 @@ mod test {
 
     #[test]
     fn oneshot_multi_thread_recv_close_stress() {
-        for stress_factor().times {
+        do stress_factor().times {
             do run_in_newsched_task {
                 let (port, chan) = oneshot::<int>();
                 let chan_cell = Cell::new(chan);
@@ -830,7 +830,7 @@ mod test {
 
     #[test]
     fn oneshot_multi_thread_send_recv_stress() {
-        for stress_factor().times {
+        do stress_factor().times {
             do run_in_newsched_task {
                 let (port, chan) = oneshot::<~int>();
                 let chan_cell = Cell::new(chan);
@@ -849,7 +849,7 @@ mod test {
 
     #[test]
     fn stream_send_recv_stress() {
-        for stress_factor().times {
+        do stress_factor().times {
             do run_in_mt_newsched_task {
                 let (port, chan) = stream::<~int>();
 
@@ -886,8 +886,8 @@ mod test {
         // Regression test that we don't run out of stack in scheduler context
         do run_in_newsched_task {
             let (port, chan) = stream();
-            for 10000.times { chan.send(()) }
-            for 10000.times { port.recv() }
+            do 10000.times { chan.send(()) }
+            do 10000.times { port.recv() }
         }
     }
 
@@ -897,14 +897,14 @@ mod test {
             let (port, chan) = stream();
             let chan = SharedChan::new(chan);
             let total = stress_factor() + 100;
-            for total.times {
+            do total.times {
                 let chan_clone = chan.clone();
                 do spawntask_random {
                     chan_clone.send(());
                 }
             }
 
-            for total.times {
+            do total.times {
                 port.recv();
             }
         }
@@ -919,7 +919,7 @@ mod test {
             let end_chan = SharedChan::new(end_chan);
             let port = SharedPort::new(port);
             let total = stress_factor() + 100;
-            for total.times {
+            do total.times {
                 let end_chan_clone = end_chan.clone();
                 let port_clone = port.clone();
                 do spawntask_random {
@@ -928,11 +928,11 @@ mod test {
                 }
             }
 
-            for total.times {
+            do total.times {
                 chan.send(());
             }
 
-            for total.times {
+            do total.times {
                 end_port.recv();
             }
         }
@@ -959,7 +959,7 @@ mod test {
             let send_total = 10;
             let recv_total = 20;
             do spawntask_random {
-                for send_total.times {
+                do send_total.times {
                     let chan_clone = chan.clone();
                     do spawntask_random {
                         chan_clone.send(());
@@ -968,7 +968,7 @@ mod test {
             }
             let end_chan_clone = end_chan.clone();
             do spawntask_random {
-                for recv_total.times {
+                do recv_total.times {
                     let port_clone = port.clone();
                     let end_chan_clone = end_chan_clone.clone();
                     do spawntask_random {
@@ -979,7 +979,7 @@ mod test {
             }
 
             let mut recvd = 0;
-            for recv_total.times {
+            do recv_total.times {
                 recvd += if end_port.recv() { 1 } else { 0 };
             }
 
@@ -998,15 +998,15 @@ mod test {
             let pipe = megapipe();
             let total = stress_factor() + 10;
             let mut rng = rand::rng();
-            for total.times {
+            do total.times {
                 let msgs = rng.gen_uint_range(0, 10);
                 let pipe_clone = pipe.clone();
                 let end_chan_clone = end_chan.clone();
                 do spawntask_random {
-                    for msgs.times {
+                    do msgs.times {
                         pipe_clone.send(());
                     }
-                    for msgs.times {
+                    do msgs.times {
                         pipe_clone.recv();
                     }
                 }
@@ -1014,7 +1014,7 @@ mod test {
                 end_chan_clone.send(());
             }
 
-            for total.times {
+            do total.times {
                 end_port.recv();
             }
         }
diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs
index 82278875fa5..1d7dafc4302 100644
--- a/src/libstd/rt/io/net/tcp.rs
+++ b/src/libstd/rt/io/net/tcp.rs
@@ -371,7 +371,7 @@ mod test {
 
             do spawntask_immediately {
                 let mut listener = TcpListener::bind(addr);
-                for max.times {
+                do max.times {
                     let mut stream = listener.accept();
                     let mut buf = [0];
                     stream.read(buf);
@@ -380,7 +380,7 @@ mod test {
             }
 
             do spawntask_immediately {
-                for max.times {
+                do max.times {
                     let mut stream = TcpStream::connect(addr);
                     stream.write([99]);
                 }
@@ -396,7 +396,7 @@ mod test {
 
             do spawntask_immediately {
                 let mut listener = TcpListener::bind(addr);
-                for max.times {
+                do max.times {
                     let mut stream = listener.accept();
                     let mut buf = [0];
                     stream.read(buf);
@@ -405,7 +405,7 @@ mod test {
             }
 
             do spawntask_immediately {
-                for max.times {
+                do max.times {
                     let mut stream = TcpStream::connect(addr);
                     stream.write([99]);
                 }
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs
index 8648832c591..3bcf6787824 100644
--- a/src/libstd/rt/mod.rs
+++ b/src/libstd/rt/mod.rs
@@ -255,7 +255,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
     // sent the Shutdown message to terminate the schedulers.
     let mut handles = ~[];
 
-    for nscheds.times {
+    do nscheds.times {
         // Every scheduler is driven by an I/O event loop.
         let loop_ = ~UvEventLoop::new();
         let mut sched = ~Scheduler::new(loop_, work_queue.clone(), sleepers.clone());
diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs
index 98df38f9b1d..ae4ca2b9783 100644
--- a/src/libstd/rt/sched.rs
+++ b/src/libstd/rt/sched.rs
@@ -1097,7 +1097,7 @@ mod test {
 
         do run_in_mt_newsched_task {
             let mut ports = ~[];
-            for 10.times {
+            do 10.times {
                 let (port, chan) = oneshot();
                 let chan_cell = Cell::new(chan);
                 do spawntask_later {
diff --git a/src/libstd/rt/select.rs b/src/libstd/rt/select.rs
index 6296186aa49..aba42ee92c3 100644
--- a/src/libstd/rt/select.rs
+++ b/src/libstd/rt/select.rs
@@ -187,7 +187,7 @@ mod test {
         do run_in_newsched_task {
             let (ports, _) = unzip(from_fn(10, |_| stream()));
             let (port, chan) = stream();
-            for 10.times { chan.send(31337); }
+            do 10.times { chan.send(31337); }
             let mut ports = ports;
             let mut port = Some(port);
             let order = [5u,0,4,3,2,6,9,8,7,1];
@@ -268,7 +268,7 @@ mod test {
 
             do run_in_newsched_task {
                 // A bit of stress, since ordinarily this is just smoke and mirrors.
-                for 4.times {
+                do 4.times {
                     let send_on_chans = send_on_chans.clone();
                     do task::spawn {
                         let mut ports = ~[];
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 894351bcc53..f0c0595744c 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -1828,7 +1828,7 @@ impl<'self> StrSlice<'self> for &'self str {
                 do ret.as_mut_buf |rbuf, _len| {
                     let mut rbuf = rbuf;
 
-                    for nn.times {
+                    do nn.times {
                         ptr::copy_memory(rbuf, buf, len);
                         rbuf = rbuf.offset(len as int);
                     }
diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs
index aff4bc12039..d0124407bd4 100644
--- a/src/libstd/task/mod.rs
+++ b/src/libstd/task/mod.rs
@@ -683,7 +683,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
         let ch = ch.clone();
         do spawn_unlinked {
             // Give middle task a chance to fail-but-not-kill-us.
-            for 16.times { task::yield(); }
+            do 16.times { task::yield(); }
             ch.send(()); // If killed first, grandparent hangs.
         }
         fail!(); // Shouldn't kill either (grand)parent or (grand)child.
@@ -698,7 +698,7 @@ fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
 fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
     do spawn_supervised { fail!(); }
     // Give child a chance to fail-but-not-kill-us.
-    for 16.times { task::yield(); }
+    do 16.times { task::yield(); }
 }
 #[test] #[should_fail] #[ignore(cfg(windows))]
 fn test_spawn_unlinked_sup_fail_down() {
@@ -760,7 +760,7 @@ fn test_spawn_failure_propagate_grandchild() {
     do spawn_supervised {
         do spawn_supervised { block_forever(); }
     }
-    for 16.times { task::yield(); }
+    do 16.times { task::yield(); }
     fail!();
 }
 
@@ -770,7 +770,7 @@ fn test_spawn_failure_propagate_secondborn() {
     do spawn_supervised {
         do spawn { block_forever(); } // linked
     }
-    for 16.times { task::yield(); }
+    do 16.times { task::yield(); }
     fail!();
 }
 
@@ -780,7 +780,7 @@ fn test_spawn_failure_propagate_nephew_or_niece() {
     do spawn { // linked
         do spawn_supervised { block_forever(); }
     }
-    for 16.times { task::yield(); }
+    do 16.times { task::yield(); }
     fail!();
 }
 
@@ -790,7 +790,7 @@ fn test_spawn_linked_sup_propagate_sibling() {
     do spawn { // linked
         do spawn { block_forever(); } // linked
     }
-    for 16.times { task::yield(); }
+    do 16.times { task::yield(); }
     fail!();
 }
 
@@ -970,7 +970,7 @@ fn test_spawn_sched_blocking() {
 
         // Testing that a task in one scheduler can block in foreign code
         // without affecting other schedulers
-        for 20u.times {
+        do 20u.times {
             let (start_po, start_ch) = stream();
             let (fin_po, fin_ch) = stream();
 
@@ -1076,7 +1076,7 @@ fn test_unkillable() {
 
     // We want to do this after failing
     do spawn_unlinked {
-        for 10.times { yield() }
+        do 10.times { yield() }
         ch.send(());
     }
 
@@ -1111,7 +1111,7 @@ fn test_unkillable_nested() {
 
     // We want to do this after failing
     do spawn_unlinked || {
-        for 10.times { yield() }
+        do 10.times { yield() }
         ch.send(());
     }
 
diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs
index a8cdd1fb2dc..5417af50081 100644
--- a/src/libstd/unstable/extfmt.rs
+++ b/src/libstd/unstable/extfmt.rs
@@ -636,7 +636,7 @@ pub mod rt {
                 buf.push_char(c);
             }
             buf.push_str(s);
-            for diff.times {
+            do diff.times {
                 buf.push_char(padchar);
             }
             return;
diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs
index e865d3a467d..f5c82bad2b1 100644
--- a/src/libstd/unstable/sync.rs
+++ b/src/libstd/unstable/sync.rs
@@ -626,7 +626,7 @@ mod tests {
             let x = Exclusive::new(~~"hello");
             let x2 = x.clone();
             do task::spawn {
-                for 10.times { task::yield(); } // try to let the unwrapper go
+                do 10.times { task::yield(); } // try to let the unwrapper go
                 fail!(); // punt it awake from its deadlock
             }
             let _z = x.unwrap();