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:
blake2-ppc 2013-08-01 04:18:19 +02:00
parent 7e210a8129
commit 78cde5b9fb
61 changed files with 137 additions and 151 deletions

View File

@ -548,7 +548,7 @@ an intermediate generation has already exited:
~~~
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# fn wait_for_a_while() { for 1000.times { task::yield() } }
# fn wait_for_a_while() { do 1000.times { task::yield() } }
# do task::try::<int> {
do task::spawn_supervised {
do task::spawn_supervised {
@ -567,7 +567,7 @@ other at all, using `task::spawn_unlinked` for _isolated failure_.
~~~
# use std::task;
# fn random() -> uint { 100 }
# fn sleep_for(i: uint) { for i.times { task::yield() } }
# fn sleep_for(i: uint) { do i.times { task::yield() } }
# do task::try::<()> {
let (time1, time2) = (random(), random());
do task::spawn_unlinked {

View File

@ -1899,7 +1899,7 @@ struct TimeBomb {
impl Drop for TimeBomb {
fn drop(&self) {
for self.explosivity.times {
do self.explosivity.times {
println("blam!");
}
}

View File

@ -23,7 +23,7 @@
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
* let shared_numbers=arc::Arc::new(numbers);
*
* for 10.times {
* do 10.times {
* let (port, chan) = stream();
* chan.send(shared_numbers.clone());
*
@ -765,7 +765,7 @@ fn test_rw_arc() {
do task::spawn || {
do arc2.write |num| {
for 10.times {
do 10.times {
let tmp = *num;
*num = -1;
task::yield();
@ -777,7 +777,7 @@ fn test_rw_arc() {
// Readers try to catch the writer in the act
let mut children = ~[];
for 5.times {
do 5.times {
let arc3 = (*arc).clone();
let mut builder = task::task();
builder.future_result(|r| children.push(r));
@ -811,7 +811,7 @@ fn test_rw_downgrade() {
// Reader tasks
let mut reader_convos = ~[];
for 10.times {
do 10.times {
let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream());
reader_convos.push((rc1, rp2));
let arcn = (*arc).clone();
@ -925,7 +925,7 @@ fn test_rw_write_cond_downgrade_read_race_helper() {
do read_mode.read |state| {
// if writer mistakenly got in, make sure it mutates state
// before we assert on it
for 5.times { task::yield(); }
do 5.times { task::yield(); }
// make sure writer didn't get in.
assert!(*state);
}
@ -937,6 +937,6 @@ fn test_rw_write_cond_downgrade_read_race() {
// helped to expose the race nearly 100% of the time... but adding
// yields in the intuitively-right locations made it even less likely,
// and I wasn't sure why :( . This is a mediocre "next best" option.
for 8.times { test_rw_write_cond_downgrade_read_race_helper() }
do 8.times { test_rw_write_cond_downgrade_read_race_helper() }
}
}

View File

@ -358,9 +358,9 @@ fn test_base64_random() {
use std::rand::{task_rng, random, RngUtil};
use std::vec;
for 1000.times {
do 1000.times {
let v: ~[u8] = do vec::build |push| {
for task_rng().gen_uint_range(1, 100).times {
do task_rng().gen_uint_range(1, 100).times {
push(random());
}
};
@ -389,4 +389,4 @@ pub fn from_base64(bh: & mut BenchHarness) {
bh.bytes = b.len() as u64;
}
}
}

View File

@ -674,7 +674,7 @@ pub fn unwrap(self) -> Bitv {
fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
fn nbits(mut w: uint) -> uint {
let mut bits = 0;
for uint::bits.times {
for uint::range(0, uint::bits) |_| {
if w == 0 {
break;
}

View File

@ -933,7 +933,7 @@ fn test_eq() {
#[test]
fn test_fuzz() {
for 25.times {
do 25.times {
fuzz_test(3);
fuzz_test(16);
fuzz_test(189);

View File

@ -90,13 +90,13 @@ mod tests {
fn test_flate_round_trip() {
let mut r = rand::rng();
let mut words = ~[];
for 20.times {
do 20.times {
let range = r.gen_uint_range(1, 10);
words.push(r.gen_bytes(range));
}
for 20.times {
do 20.times {
let mut input = ~[];
for 2000.times {
do 2000.times {
input.push_all(r.choose(words));
}
debug!("de/inflate of %u bytes of random word-sequences",

View File

@ -662,7 +662,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
// here we just need to indent the start of the description
let rowlen = row.len();
if rowlen < 24 {
for (24 - rowlen).times {
do (24 - rowlen).times {
row.push_char(' ')
}
} else {

View File

@ -77,7 +77,7 @@ fn escape_str(s: &str) -> ~str {
fn spaces(n: uint) -> ~str {
let mut ss = ~"";
for n.times {
do n.times {
ss.push_str(" ");
}
return ss;

View File

@ -509,7 +509,7 @@ fn bench_push_front(b: &mut test::BenchHarness) {
fn bench_grow(b: &mut test::BenchHarness) {
let mut deq = RingBuf::new();
do b.iter {
for 65.times {
do 65.times {
deq.push_front(1);
}
}

View File

@ -1081,7 +1081,7 @@ fn isSorted<T:Ord>(arr: &[T]) {
tim_sort(arr); // /sort
isSorted(arr);
for 3.times {
do 3.times {
let i1 = rng.gen_uint_range(0, n);
let i2 = rng.gen_uint_range(0, n);
arr.swap(i1, i2);
@ -1100,7 +1100,7 @@ fn isSorted<T:Ord>(arr: &[T]) {
tim_sort(arr); // +sort
isSorted(arr);
for (n/100).times {
do (n/100).times {
let idx = rng.gen_uint_range(0, n);
arr[idx] = rng.gen();
}
@ -1153,7 +1153,7 @@ fn isSorted<T:Ord>(arr: &[@T]) {
tim_sort(arr); // /sort
isSorted(arr);
for 3.times {
do 3.times {
let i1 = rng.gen_uint_range(0, n);
let i2 = rng.gen_uint_range(0, n);
arr.swap(i1, i2);
@ -1172,7 +1172,7 @@ fn isSorted<T:Ord>(arr: &[@T]) {
tim_sort(arr); // +sort
isSorted(arr);
for (n/100).times {
do (n/100).times {
let idx = rng.gen_uint_range(0, n);
arr[idx] = @rng.gen();
}

View File

@ -106,7 +106,7 @@ pub fn acquire(&self) {
}
}
// Uncomment if you wish to test for sem races. Not valgrind-friendly.
/* for 1000.times { task::yield(); } */
/* do 1000.times { task::yield(); } */
// Need to wait outside the exclusive.
if waiter_nobe.is_some() {
let _ = comm::recv_one(waiter_nobe.unwrap());
@ -143,7 +143,7 @@ impl Sem<~[WaitQueue]> {
fn new_and_signal(count: int, num_condvars: uint)
-> Sem<~[WaitQueue]> {
let mut queues = ~[];
for num_condvars.times {
do num_condvars.times {
queues.push(WaitQueue::new());
}
Sem::new(count, queues)
@ -826,11 +826,11 @@ fn test_sem_as_mutex() {
let s2 = ~s.clone();
do task::spawn || {
do s2.access {
for 5.times { task::yield(); }
do 5.times { task::yield(); }
}
}
do s.access {
for 5.times { task::yield(); }
do 5.times { task::yield(); }
}
}
#[test]
@ -843,7 +843,7 @@ fn test_sem_as_cvar() {
s2.acquire();
c.send(());
}
for 5.times { task::yield(); }
do 5.times { task::yield(); }
s.release();
let _ = p.recv();
@ -852,7 +852,7 @@ fn test_sem_as_cvar() {
let s = ~Semaphore::new(0);
let s2 = ~s.clone();
do task::spawn || {
for 5.times { task::yield(); }
do 5.times { task::yield(); }
s2.release();
let _ = p.recv();
}
@ -895,7 +895,7 @@ fn test_sem_runtime_friendly_blocking() {
c.send(());
}
let _ = p.recv(); // wait for child to come alive
for 5.times { task::yield(); } // let the child contend
do 5.times { task::yield(); } // let the child contend
}
let _ = p.recv(); // wait for child to be done
}
@ -929,7 +929,7 @@ fn test_mutex_lock() {
}
fn access_shared(sharedstate: &mut int, m: &Mutex, n: uint) {
for n.times {
do n.times {
do m.lock {
let oldval = *sharedstate;
task::yield();
@ -975,7 +975,7 @@ fn test_mutex_cond_broadcast_helper(num_waiters: uint) {
let m = ~Mutex::new();
let mut ports = ~[];
for num_waiters.times {
do num_waiters.times {
let mi = ~m.clone();
let (port, chan) = comm::stream();
ports.push(port);
@ -1065,7 +1065,7 @@ fn test_mutex_killed_broadcast() {
let result: result::Result<(),()> = do task::try || {
let mut sibling_convos = ~[];
for 2.times {
do 2.times {
let (p,c) = comm::stream();
let c = Cell::new(c);
sibling_convos.push(p);
@ -1212,7 +1212,7 @@ fn test_rwlock_exclusion(x: ~RWLock,
fn access_shared(sharedstate: &mut int, x: &RWLock, mode: RWLockMode,
n: uint) {
for n.times {
do n.times {
do lock_rwlock_in_mode(x, mode) {
let oldval = *sharedstate;
task::yield();
@ -1343,7 +1343,7 @@ fn lock_cond(x: &RWLock, downgrade: bool, blk: &fn(c: &Condvar)) {
let x = ~RWLock::new();
let mut ports = ~[];
for num_waiters.times {
do num_waiters.times {
let xi = (*x).clone();
let (port, chan) = comm::stream();
ports.push(port);

View File

@ -102,7 +102,7 @@ fn test_task_pool() {
g
};
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
for 8.times {
do 8.times {
pool.execute(|i| printfln!("Hello from thread %u!", *i));
}
}

View File

@ -14,12 +14,13 @@
use std::os;
use std::rand::RngUtil;
use std::rand;
use std::uint;
/// Attempts to make a temporary directory inside of `tmpdir` whose name will
/// have the suffix `suffix`. If no directory can be created, None is returned.
pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
let mut r = rand::rng();
for 1000.times {
for uint::range(0, 1000) |_| {
let p = tmpdir.push(r.gen_str(16) + suffix);
if os::make_dir(&p, 0x1c0) { // 700
return Some(p);

View File

@ -16,6 +16,7 @@
use std::num;
use std::util::{swap, replace};
use std::iterator::{FromIterator, Extendable};
use std::uint;
// This is implemented as an AA tree, which is a simplified variation of
// a red-black tree where red (horizontal) nodes can only be added
@ -47,7 +48,7 @@ fn eq(&self, other: &TreeMap<K, V>) -> bool {
} else {
let mut x = self.iter();
let mut y = other.iter();
for self.len().times {
for uint::range(0, self.len()) |_| {
if x.next().unwrap() != y.next().unwrap() {
return false
}
@ -65,7 +66,7 @@ fn lt<K: Ord + TotalOrd, V: Ord>(a: &TreeMap<K, V>,
let mut y = b.iter();
let (a_len, b_len) = (a.len(), b.len());
for num::min(a_len, b_len).times {
for uint::range(0, num::min(a_len, b_len)) |_| {
let (key_a, value_a) = x.next().unwrap();
let (key_b, value_b) = y.next().unwrap();
if *key_a < *key_b { return true; }
@ -931,8 +932,8 @@ fn test_rand_int() {
let mut rng = rand::IsaacRng::new_seeded(&[42]);
for 3.times {
for 90.times {
do 3.times {
do 90.times {
let k = rng.gen();
let v = rng.gen();
if !ctrl.iter().any(|x| x == &(k, v)) {
@ -943,7 +944,7 @@ fn test_rand_int() {
}
}
for 30.times {
do 30.times {
let r = rng.gen_uint_range(0, ctrl.len());
let (key, _) = ctrl.remove(r);
assert!(map.remove(&key));

View File

@ -189,7 +189,7 @@ fn compute_id_range(&mut self, id: ast::NodeId) -> (uint, uint) {
};
if expanded {
let entry = if self.oper.initial_value() { uint::max_value } else {0};
for self.words_per_id.times {
do self.words_per_id.times {
self.gens.push(0);
self.kills.push(0);
self.on_entry.push(entry);

View File

@ -451,7 +451,7 @@ fn with_lint_attrs(@mut self, attrs: &[ast::Attribute], f: &fn()) {
if doc_hidden && self.doc_hidden {
self.doc_hidden = false;
}
for pushed.times {
do pushed.times {
let (lint, lvl, src) = self.lint_stack.pop();
self.set_level(lint, lvl, src);
}

View File

@ -340,7 +340,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
visit::visit_mod(the_module, span, node_id, (method_map, visitor));
for n_added.times {
do n_added.times {
ignore(privileged_items.pop());
}
},
@ -370,7 +370,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
visit::visit_block(block, (method_map, visitor));
for n_added.times {
do n_added.times {
ignore(privileged_items.pop());
}
},

View File

@ -188,7 +188,7 @@ pub fn const_expr(cx: @mut CrateContext, e: @ast::expr) -> ValueRef {
Some(@ty::AutoDerefRef(ref adj)) => {
let mut ty = ety;
let mut maybe_ptr = None;
for adj.autoderefs.times {
do adj.autoderefs.times {
let (dv, dt) = const_deref(cx, llconst, ty, false);
maybe_ptr = Some(llconst);
llconst = dv;

View File

@ -637,7 +637,7 @@ fn should_request_new_writer_for_each_page() {
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
write_markdown(doc, writer_factory);
// We expect two pages to have been written
for 2.times {
do 2.times {
po.recv();
}
}
@ -649,7 +649,7 @@ fn should_write_title_for_each_page() {
~"#[link(name = \"core\")]; mod a { }");
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
write_markdown(doc, writer_factory);
for 2.times {
do 2.times {
let (page, markdown) = po.recv();
match page {
doc::CratePage(_) => {

View File

@ -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());
}

View File

@ -18,7 +18,6 @@
*/
use cmp;
use iter::Times;
use num::{Zero, One};
use option::{Option, Some, None};
use ops::{Add, Mul};
@ -1229,8 +1228,9 @@ fn next(&mut self) -> Option<A> {
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();

View File

@ -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));
}

View File

@ -695,7 +695,7 @@ macro_rules! mix(
}}
);
for 4.times { mix!(); }
do 4.times { mix!(); }
if use_rsl {
macro_rules! memloop (
@ -1092,7 +1092,7 @@ pub unsafe fn rand_new_seeded(buf: *u8, sz: size_t)
}
// 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 @@ pub unsafe fn rand_new_seeded(buf: *u8, sz: size_t)
};
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);

View File

@ -769,7 +769,7 @@ fn oneshot_multi_task_recv_then_close() {
#[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 @@ fn oneshot_multi_thread_close_stress() {
#[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 @@ fn oneshot_multi_thread_send_close_stress() {
#[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 @@ fn oneshot_multi_thread_recv_close_stress() {
#[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 @@ fn oneshot_multi_thread_send_recv_stress() {
#[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 @@ fn recv_a_lot() {
// 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 @@ fn shared_chan_stress() {
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 @@ fn shared_port_stress() {
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 @@ fn shared_port_stress() {
}
}
for total.times {
do total.times {
chan.send(());
}
for total.times {
do total.times {
end_port.recv();
}
}
@ -959,7 +959,7 @@ fn shared_port_close() {
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 @@ fn shared_port_close() {
}
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 @@ fn shared_port_close() {
}
let mut recvd = 0;
for recv_total.times {
do recv_total.times {
recvd += if end_port.recv() { 1 } else { 0 };
}
@ -998,15 +998,15 @@ fn megapipe_stress() {
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 @@ fn megapipe_stress() {
end_chan_clone.send(());
}
for total.times {
do total.times {
end_port.recv();
}
}

View File

@ -371,7 +371,7 @@ fn multiple_connect_serial_ip4() {
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 @@ fn multiple_connect_serial_ip4() {
}
do spawntask_immediately {
for max.times {
do max.times {
let mut stream = TcpStream::connect(addr);
stream.write([99]);
}
@ -396,7 +396,7 @@ fn multiple_connect_serial_ip6() {
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 @@ fn multiple_connect_serial_ip6() {
}
do spawntask_immediately {
for max.times {
do max.times {
let mut stream = TcpStream::connect(addr);
stream.write([99]);
}

View File

@ -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());

View File

@ -1097,7 +1097,7 @@ fn multithreading() {
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 {

View File

@ -187,7 +187,7 @@ fn select_stream() {
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 @@ fn select_racing_senders_helper(killable: bool, send_on_chans: ~[uint]) {
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 = ~[];

View File

@ -1828,7 +1828,7 @@ fn repeat(&self, nn: uint) -> ~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);
}

View File

@ -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(());
}

View File

@ -636,7 +636,7 @@ pub fn pad(cv: Conv, s: &str, head: Option<char>, mode: PadMode,
buf.push_char(c);
}
buf.push_str(s);
for diff.times {
do diff.times {
buf.push_char(padchar);
}
return;

View File

@ -626,7 +626,7 @@ fn exclusive_new_unwrap_deadlock() {
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();

View File

@ -302,7 +302,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
// Skip is the number of characters we need to skip because they are
// part of the 'filename:line ' part of the previous line.
let skip = fm.name.len() + digits + 3u;
for skip.times() {
do skip.times() {
s.push_char(' ');
}
let orig = fm.get_line(lines.lines[0] as int);
@ -323,7 +323,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
if hi.col != lo.col {
// the ^ already takes up one space
let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u;
for num_squigglies.times() {
do num_squigglies.times() {
s.push_char('~')
}
}

View File

@ -403,7 +403,7 @@ pub fn parse(
}
cur_eis.push(ei);
for rust_parser.tokens_consumed.times() || {
do rust_parser.tokens_consumed.times() || {
rdr.next_token();
}
}

View File

@ -59,7 +59,7 @@ pub fn bench_int<T:MutableSet<uint>,
{
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 @@ pub fn bench_str<T:MutableSet<~str>,
{
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);
}

View File

@ -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(

View File

@ -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();

View File

@ -164,7 +164,7 @@ fn make(&mut self, n: uint) {
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();
}

View File

@ -54,7 +54,7 @@ fn pack(string: &str) -> 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);
}

View File

@ -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;
}

View File

@ -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];

View File

@ -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);
}

View File

@ -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)

View File

@ -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();

View File

@ -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
}
}

View File

@ -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;

View File

@ -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
}

View File

@ -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);

View File

@ -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() {

View File

@ -69,7 +69,7 @@ pub fn main() {
roundtrip::<C>();
roundtrip::<D>();
for 20.times {
do 20.times {
roundtrip::<E>();
roundtrip::<F>();
roundtrip::<G<int>>();

View File

@ -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>();

View File

@ -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);
};

View File

@ -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);

View File

@ -1,6 +1,6 @@
pub fn main() {
let mut x = 0;
for 4096.times {
do 4096.times {
x += 1;
}
assert_eq!(x, 4096);

View File

@ -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, '.'));
}
};

View File

@ -45,7 +45,7 @@ enum 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),

View File

@ -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);

View File

@ -14,7 +14,7 @@ trait Fooable {
impl Fooable for uint {
fn yes(self) {
for self.times {
do self.times {
println("yes");
}
}

View File

@ -32,7 +32,7 @@ pub fn main() {
assert_eq!(15u64.add(&6u64), 21u64);
// times
15u.times(|| false);
15u.times(|| {});
// floats
// num

View File

@ -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));
}