about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-01-30 11:20:34 +1100
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-01-30 14:52:25 +1100
commit729060dbb95afd1d8562a6b3129555a173b81b0c (patch)
tree0530d4f7fe149f68b4a910d340b44b7404a0d748 /src/libstd
parentdfb61166f5a62845e7edc71ac533a4d3a35afebc (diff)
downloadrust-729060dbb95afd1d8562a6b3129555a173b81b0c.tar.gz
rust-729060dbb95afd1d8562a6b3129555a173b81b0c.zip
Remove Times trait
`Times::times` was always a second-class loop because it did not support the `break` and `continue` operations. Its playful appeal was then lost after `do` was disabled for closures. It's time to let this one go.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/comm/mod.rs32
-rw-r--r--src/libstd/comm/select.rs6
-rw-r--r--src/libstd/io/net/tcp.rs12
-rw-r--r--src/libstd/io/net/unix.rs8
-rw-r--r--src/libstd/num/mod.rs12
-rw-r--r--src/libstd/num/uint.rs31
-rw-r--r--src/libstd/prelude.rs1
-rw-r--r--src/libstd/rand/isaac.rs3
8 files changed, 30 insertions, 75 deletions
diff --git a/src/libstd/comm/mod.rs b/src/libstd/comm/mod.rs
index 8c56e65c22c..7f8f74f1b64 100644
--- a/src/libstd/comm/mod.rs
+++ b/src/libstd/comm/mod.rs
@@ -1227,17 +1227,17 @@ mod test {
     })
 
     test!(fn oneshot_multi_thread_close_stress() {
-        stress_factor().times(|| {
+        for _ in range(0, stress_factor()) {
             let (port, chan) = Chan::<int>::new();
             spawn(proc() {
                 let _p = port;
             });
             let _chan = chan;
-        })
+        }
     })
 
     test!(fn oneshot_multi_thread_send_close_stress() {
-        stress_factor().times(|| {
+        for _ in range(0, stress_factor()) {
             let (port, chan) = Chan::<int>::new();
             spawn(proc() {
                 let _p = port;
@@ -1245,11 +1245,11 @@ mod test {
             task::try(proc() {
                 chan.send(1);
             });
-        })
+        }
     })
 
     test!(fn oneshot_multi_thread_recv_close_stress() {
-        stress_factor().times(|| {
+        for _ in range(0, stress_factor()) {
             let (port, chan) = Chan::<int>::new();
             spawn(proc() {
                 let port = port;
@@ -1264,11 +1264,11 @@ mod test {
                     let _chan = chan;
                 });
             });
-        })
+        }
     })
 
     test!(fn oneshot_multi_thread_send_recv_stress() {
-        stress_factor().times(|| {
+        for _ in range(0, stress_factor()) {
             let (port, chan) = Chan::<~int>::new();
             spawn(proc() {
                 chan.send(~10);
@@ -1276,11 +1276,11 @@ mod test {
             spawn(proc() {
                 assert!(port.recv() == ~10);
             });
-        })
+        }
     })
 
     test!(fn stream_send_recv_stress() {
-        stress_factor().times(|| {
+        for _ in range(0, stress_factor()) {
             let (port, chan) = Chan::<~int>::new();
 
             send(chan, 0);
@@ -1303,29 +1303,29 @@ mod test {
                     recv(port, i + 1);
                 });
             }
-        })
+        }
     })
 
     test!(fn recv_a_lot() {
         // Regression test that we don't run out of stack in scheduler context
         let (port, chan) = Chan::new();
-        10000.times(|| { chan.send(()) });
-        10000.times(|| { port.recv() });
+        for _ in range(0, 10000) { chan.send(()); }
+        for _ in range(0, 10000) { port.recv(); }
     })
 
     test!(fn shared_chan_stress() {
         let (port, chan) = SharedChan::new();
         let total = stress_factor() + 100;
-        total.times(|| {
+        for _ in range(0, total) {
             let chan_clone = chan.clone();
             spawn(proc() {
                 chan_clone.send(());
             });
-        });
+        }
 
-        total.times(|| {
+        for _ in range(0, total) {
             port.recv();
-        });
+        }
     })
 
     test!(fn test_nested_recv_iter() {
diff --git a/src/libstd/comm/select.rs b/src/libstd/comm/select.rs
index af435c3fc5f..a0db70117aa 100644
--- a/src/libstd/comm/select.rs
+++ b/src/libstd/comm/select.rs
@@ -379,10 +379,10 @@ mod test {
         let (p3, c3) = Chan::<int>::new();
 
         spawn(proc() {
-            20.times(task::deschedule);
+            for _ in range(0, 20) { task::deschedule(); }
             c1.send(1);
             p3.recv();
-            20.times(task::deschedule);
+            for _ in range(0, 20) { task::deschedule(); }
         });
 
         select! (
@@ -402,7 +402,7 @@ mod test {
         let (p3, c3) = Chan::<()>::new();
 
         spawn(proc() {
-            20.times(task::deschedule);
+            for _ in range(0, 20) { task::deschedule(); }
             c1.send(1);
             c2.send(2);
             p3.recv();
diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs
index 2d074df4919..fc608ce25a6 100644
--- a/src/libstd/io/net/tcp.rs
+++ b/src/libstd/io/net/tcp.rs
@@ -355,15 +355,15 @@ mod test {
 
     iotest!(fn multiple_connect_serial_ip4() {
         let addr = next_test_ip4();
-        let max = 10;
+        let max = 10u;
         let (port, chan) = Chan::new();
 
         spawn(proc() {
             port.recv();
-            max.times(|| {
+            for _ in range(0, max) {
                 let mut stream = TcpStream::connect(addr);
                 stream.write([99]);
-            });
+            }
         });
 
         let mut acceptor = TcpListener::bind(addr).listen();
@@ -377,15 +377,15 @@ mod test {
 
     iotest!(fn multiple_connect_serial_ip6() {
         let addr = next_test_ip6();
-        let max = 10;
+        let max = 10u;
         let (port, chan) = Chan::new();
 
         spawn(proc() {
             port.recv();
-            max.times(|| {
+            for _ in range(0, max) {
                 let mut stream = TcpStream::connect(addr);
                 stream.write([99]);
-            });
+            }
         });
 
         let mut acceptor = TcpListener::bind(addr).listen();
diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs
index dcf6d2ad203..d470e9bfda1 100644
--- a/src/libstd/io/net/unix.rs
+++ b/src/libstd/io/net/unix.rs
@@ -234,20 +234,20 @@ mod tests {
 
         spawn(proc() {
             port.recv();
-            times.times(|| {
+            for _ in range(0, times) {
                 let mut stream = UnixStream::connect(&path2);
                 stream.write([100]);
-            })
+            }
         });
 
         let mut acceptor = UnixListener::bind(&path1).listen();
         chan.send(());
-        times.times(|| {
+        for _ in range(0, times) {
             let mut client = acceptor.accept();
             let mut buf = [0];
             client.read(buf);
             assert_eq!(buf[0], 100);
-        })
+        }
     }
 
     #[test]
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs
index 478029b8561..28f0cfbce15 100644
--- a/src/libstd/num/mod.rs
+++ b/src/libstd/num/mod.rs
@@ -139,18 +139,6 @@ pub trait Signed: Num
 
 pub trait Unsigned: Num {}
 
-/// Times trait
-///
-/// ```rust
-/// let ten = 10u;
-/// let mut accum = 0;
-/// ten.times(|| { accum += 1; })
-/// ```
-///
-pub trait Times {
-    fn times(&self, it: ||);
-}
-
 pub trait Integer: Num
                  + Orderable
                  + Div<Self,Self>
diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs
index 3eeae6283b3..89914571ada 100644
--- a/src/libstd/num/uint.rs
+++ b/src/libstd/num/uint.rs
@@ -20,7 +20,6 @@ use num::{Bitwise, Bounded};
 use num::{CheckedAdd, CheckedSub, CheckedMul};
 use num::{CheckedDiv, Zero, One, strconv};
 use num::{ToStrRadix, FromStrRadix};
-use num;
 use option::{Option, Some, None};
 use str;
 use unstable::intrinsics;
@@ -80,27 +79,6 @@ pub fn div_round(x: uint, y: uint) -> uint {
 ///
 pub fn div_floor(x: uint, y: uint) -> uint { return x / y; }
 
-impl num::Times for uint {
-    #[inline]
-    ///
-    /// A convenience form for basic repetition. Given a uint `x`,
-    /// `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. `100.times(|| { ... })`).
-    ///
-    fn times(&self, it: ||) {
-        let mut i = *self;
-        while i > 0 {
-            it();
-            i -= 1;
-        }
-    }
-}
-
 /// Returns the smallest power of 2 greater than or equal to `n`
 #[inline]
 pub fn next_power_of_two(n: uint) -> uint {
@@ -245,12 +223,3 @@ fn test_div() {
     assert!((div_ceil(3u, 4u)  == 1u));
     assert!((div_round(3u, 4u) == 1u));
 }
-
-#[test]
-pub fn test_times() {
-    use num::Times;
-    let ten = 10 as uint;
-    let mut accum = 0;
-    ten.times(|| { accum += 1; });
-    assert!((accum == 10));
-}
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index 2f5f3e8f456..d750e8ed406 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -57,7 +57,6 @@ pub use hash::Hash;
 pub use iter::{FromIterator, Extendable};
 pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
 pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
-pub use num::Times;
 pub use num::{Integer, Real, Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
 pub use num::{Orderable, Signed, Unsigned, Round};
 pub use num::{Primitive, Int, Float, ToStrRadix, ToPrimitive, FromPrimitive};
diff --git a/src/libstd/rand/isaac.rs b/src/libstd/rand/isaac.rs
index 6fd2cde9dfb..9871207a91e 100644
--- a/src/libstd/rand/isaac.rs
+++ b/src/libstd/rand/isaac.rs
@@ -12,7 +12,6 @@
 
 use rand::{Rng, SeedableRng, OSRng};
 use iter::{Iterator, range, range_step, Repeat};
-use num::Times;
 use option::{None, Some};
 use vec::{raw, MutableVector, ImmutableVector};
 use mem;
@@ -95,7 +94,7 @@ impl IsaacRng {
             }}
         );
 
-        4.times(|| mix!());
+        for _ in range(0, 4) { mix!(); }
 
         if use_rsl {
             macro_rules! memloop (