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.
This commit is contained in:
parent
7e210a8129
commit
78cde5b9fb
61 changed files with 137 additions and 151 deletions
|
|
@ -59,7 +59,7 @@ impl Results {
|
|||
{
|
||||
let mut set = f();
|
||||
do timed(&mut self.random_ints) {
|
||||
for num_keys.times {
|
||||
do num_keys.times {
|
||||
set.insert((rng.next() as uint) % rand_cap);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ impl Results {
|
|||
{
|
||||
let mut set = f();
|
||||
do timed(&mut self.random_strings) {
|
||||
for num_keys.times {
|
||||
do num_keys.times {
|
||||
let s = uint::to_str(rng.next() as uint);
|
||||
set.insert(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ fn main() {
|
|||
let symbols = [" ", "░", "▒", "▓", "█", "█"];
|
||||
let mut pixels = [0f32, ..256*256];
|
||||
let n2d = ~Noise2DContext::new();
|
||||
for 100.times {
|
||||
do 100.times {
|
||||
for int::range(0, 256) |y| {
|
||||
for int::range(0, 256) |x| {
|
||||
let v = n2d.get(
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
|||
let mut creatures_met = 0;
|
||||
|
||||
// set up meetings...
|
||||
for nn.times {
|
||||
do nn.times {
|
||||
let fst_creature: CreatureInfo = from_creatures.recv();
|
||||
let snd_creature: CreatureInfo = from_creatures.recv();
|
||||
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ impl RandomFasta {
|
|||
let chars_left = n % LINE_LEN;
|
||||
let mut buf = [0, ..LINE_LEN + 1];
|
||||
|
||||
for lines.times {
|
||||
do lines.times {
|
||||
for range(0, LINE_LEN) |i| {
|
||||
buf[i] = self.nextc();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ impl Code {
|
|||
fn unpack(&self, frame: i32) -> ~str {
|
||||
let mut key = **self;
|
||||
let mut result = ~[];
|
||||
for (frame as uint).times {
|
||||
do (frame as uint).times {
|
||||
result.push(unpack_symbol((key as u8) & 3));
|
||||
key >>= 2;
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ fn generate_frequencies(frequencies: &mut Table,
|
|||
let mut code = Code(0);
|
||||
|
||||
// Pull first frame.
|
||||
for (frame as uint).times {
|
||||
do (frame as uint).times {
|
||||
code = code.push_char(input[0]);
|
||||
input = next_char(input);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ fn main() {
|
|||
let Cr = 2.0 * (x as f64) / (w as f64) - 1.5;
|
||||
let Ci = 2.0 * (y as f64) / (h as f64) - 1.0;
|
||||
|
||||
for ITER.times {
|
||||
for range(0, ITER as i32) |_| {
|
||||
if Tr + Ti > LIMIT * LIMIT {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ struct Planet {
|
|||
|
||||
fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
|
||||
let mut d = [ 0.0, ..3 ];
|
||||
for (steps as uint).times {
|
||||
do (steps as uint).times {
|
||||
for range(0, N_BODIES) |i| {
|
||||
for range(i + 1, N_BODIES) |j| {
|
||||
d[0] = bodies[i].x[0] - bodies[j].x[0];
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ fn main() {
|
|||
let mut u = vec::from_elem(n, 1f64);
|
||||
let mut v = u.clone();
|
||||
let mut tmp = u.clone();
|
||||
for 8.times {
|
||||
do 8.times {
|
||||
mult_AtAv(u, v, tmp);
|
||||
mult_AtAv(v, u, tmp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn run(repeat: int, depth: int) {
|
||||
for (repeat as uint).times {
|
||||
do (repeat as uint).times {
|
||||
info!("starting %.4f", precise_time_s());
|
||||
do task::try {
|
||||
recurse_or_fail(depth, None)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ fn grandchild_group(num_tasks: uint) {
|
|||
let (po, ch) = stream();
|
||||
let ch = SharedChan::new(ch);
|
||||
|
||||
for num_tasks.times {
|
||||
do num_tasks.times {
|
||||
let ch = ch.clone();
|
||||
do task::spawn { // linked
|
||||
ch.send(());
|
||||
|
|
@ -41,7 +41,7 @@ fn grandchild_group(num_tasks: uint) {
|
|||
}
|
||||
}
|
||||
error!("Grandchild group getting started");
|
||||
for num_tasks.times {
|
||||
do num_tasks.times {
|
||||
// Make sure all above children are fully spawned; i.e., enlisted in
|
||||
// their ancestor groups.
|
||||
po.recv();
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
for 2.times { //~ ERROR A for-loop body must return (), but
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ fn block_overarching_alias_mut() {
|
|||
|
||||
let mut v = ~3;
|
||||
let mut x = &mut v;
|
||||
for 3.times {
|
||||
do 3.times {
|
||||
borrow(v); //~ ERROR cannot borrow
|
||||
}
|
||||
*x = ~5;
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
do 5.times {}; //~ ERROR Do-block body must return bool, but returns () here. Perhaps
|
||||
fn take_block(f: &fn() -> bool) -> bool { f() }
|
||||
do take_block {}; //~ ERROR Do-block body must return bool, but returns () here. Perhaps
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ fn count(n: uint) -> uint {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
for 10u.times {
|
||||
do 10u.times {
|
||||
do task::spawn {
|
||||
let result = count(5u);
|
||||
info!("result = %?", result);
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@
|
|||
extern mod extra;
|
||||
use extra::bitv::*;
|
||||
|
||||
fn bitv_test() -> bool {
|
||||
fn bitv_test() {
|
||||
let mut v1 = ~Bitv::new(31, false);
|
||||
let v2 = ~Bitv::new(31, true);
|
||||
v1.union(v2);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ pub fn main() {
|
|||
roundtrip::<C>();
|
||||
roundtrip::<D>();
|
||||
|
||||
for 20.times {
|
||||
do 20.times {
|
||||
roundtrip::<E>();
|
||||
roundtrip::<F>();
|
||||
roundtrip::<G<int>>();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ enum D {
|
|||
|
||||
fn main() {
|
||||
// check there's no segfaults
|
||||
for 20.times {
|
||||
do 20.times {
|
||||
rand::random::<A>();
|
||||
rand::random::<B>();
|
||||
rand::random::<C>();
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ fn count(n: uint) -> uint {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
for 100u.times {
|
||||
do 100u.times {
|
||||
do task::spawn {
|
||||
assert_eq!(count(5u), 16u);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ fn count(n: uint) -> uint {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
for 10u.times {
|
||||
do 10u.times {
|
||||
do task::spawn {
|
||||
let result = count(5u);
|
||||
info!("result = %?", result);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
pub fn main() {
|
||||
let mut x = 0;
|
||||
for 4096.times {
|
||||
do 4096.times {
|
||||
x += 1;
|
||||
}
|
||||
assert_eq!(x, 4096);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt {
|
|||
// Use an anonymous function to build a vector of vectors containing
|
||||
// blank characters for each position in our canvas.
|
||||
let mut lines = do vec::build_sized(height) |push| {
|
||||
for height.times {
|
||||
do height.times {
|
||||
push(vec::from_elem(width, '.'));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ priv fn parse_data(len: uint, io: @io::Reader) -> Result {
|
|||
|
||||
priv fn parse_list(len: uint, io: @io::Reader) -> Result {
|
||||
let mut list: ~[Result] = ~[];
|
||||
for len.times {
|
||||
do len.times {
|
||||
let v =
|
||||
match io.read_char() {
|
||||
'$' => parse_bulk(io),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
pub fn main() {
|
||||
let mut count = 0;
|
||||
for 999_999.times() {
|
||||
do 999_999.times() {
|
||||
count += 1;
|
||||
}
|
||||
assert_eq!(count, 999_999);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ trait Fooable {
|
|||
|
||||
impl Fooable for uint {
|
||||
fn yes(self) {
|
||||
for self.times {
|
||||
do self.times {
|
||||
println("yes");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub fn main() {
|
|||
assert_eq!(15u64.add(&6u64), 21u64);
|
||||
|
||||
// times
|
||||
15u.times(|| false);
|
||||
15u.times(|| {});
|
||||
|
||||
// floats
|
||||
// num
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ fn more_floats() {
|
|||
}
|
||||
|
||||
fn pointer() {
|
||||
for 10.times {
|
||||
do 10.times {
|
||||
let x: uint = ::std::rand::random();
|
||||
assert_eq!(fmt!("%p", x as *uint), fmt!("0x%x", x));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue