Skip to content

Commit 78cde5b

Browse files
author
blake2-ppc
committed
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.
1 parent 7e210a8 commit 78cde5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+137
-151
lines changed

doc/tutorial-tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ an intermediate generation has already exited:
548548
~~~
549549
# use std::task;
550550
# fn sleep_forever() { loop { task::yield() } }
551-
# fn wait_for_a_while() { for 1000.times { task::yield() } }
551+
# fn wait_for_a_while() { do 1000.times { task::yield() } }
552552
# do task::try::<int> {
553553
do task::spawn_supervised {
554554
do task::spawn_supervised {
@@ -567,7 +567,7 @@ other at all, using `task::spawn_unlinked` for _isolated failure_.
567567
~~~
568568
# use std::task;
569569
# fn random() -> uint { 100 }
570-
# fn sleep_for(i: uint) { for i.times { task::yield() } }
570+
# fn sleep_for(i: uint) { do i.times { task::yield() } }
571571
# do task::try::<()> {
572572
let (time1, time2) = (random(), random());
573573
do task::spawn_unlinked {

doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ struct TimeBomb {
18991899
19001900
impl Drop for TimeBomb {
19011901
fn drop(&self) {
1902-
for self.explosivity.times {
1902+
do self.explosivity.times {
19031903
println("blam!");
19041904
}
19051905
}

src/libextra/arc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
2424
* let shared_numbers=arc::Arc::new(numbers);
2525
*
26-
* for 10.times {
26+
* do 10.times {
2727
* let (port, chan) = stream();
2828
* chan.send(shared_numbers.clone());
2929
*
@@ -765,7 +765,7 @@ mod tests {
765765
766766
do task::spawn || {
767767
do arc2.write |num| {
768-
for 10.times {
768+
do 10.times {
769769
let tmp = *num;
770770
*num = -1;
771771
task::yield();
@@ -777,7 +777,7 @@ mod tests {
777777
778778
// Readers try to catch the writer in the act
779779
let mut children = ~[];
780-
for 5.times {
780+
do 5.times {
781781
let arc3 = (*arc).clone();
782782
let mut builder = task::task();
783783
builder.future_result(|r| children.push(r));
@@ -811,7 +811,7 @@ mod tests {
811811
812812
// Reader tasks
813813
let mut reader_convos = ~[];
814-
for 10.times {
814+
do 10.times {
815815
let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream());
816816
reader_convos.push((rc1, rp2));
817817
let arcn = (*arc).clone();
@@ -925,7 +925,7 @@ mod tests {
925925
do read_mode.read |state| {
926926
// if writer mistakenly got in, make sure it mutates state
927927
// before we assert on it
928-
for 5.times { task::yield(); }
928+
do 5.times { task::yield(); }
929929
// make sure writer didn't get in.
930930
assert!(*state);
931931
}
@@ -937,6 +937,6 @@ mod tests {
937937
// helped to expose the race nearly 100% of the time... but adding
938938
// yields in the intuitively-right locations made it even less likely,
939939
// and I wasn't sure why :( . This is a mediocre "next best" option.
940-
for 8.times { test_rw_write_cond_downgrade_read_race_helper() }
940+
do 8.times { test_rw_write_cond_downgrade_read_race_helper() }
941941
}
942942
}

src/libextra/base64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ mod test {
358358
use std::rand::{task_rng, random, RngUtil};
359359
use std::vec;
360360
361-
for 1000.times {
361+
do 1000.times {
362362
let v: ~[u8] = do vec::build |push| {
363-
for task_rng().gen_uint_range(1, 100).times {
363+
do task_rng().gen_uint_range(1, 100).times {
364364
push(random());
365365
}
366366
};
@@ -389,4 +389,4 @@ mod test {
389389
bh.bytes = b.len() as u64;
390390
}
391391

392-
}
392+
}

src/libextra/bitv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl BitvSet {
674674
fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
675675
fn nbits(mut w: uint) -> uint {
676676
let mut bits = 0;
677-
for uint::bits.times {
677+
for uint::range(0, uint::bits) |_| {
678678
if w == 0 {
679679
break;
680680
}

src/libextra/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ mod tests {
933933

934934
#[test]
935935
fn test_fuzz() {
936-
for 25.times {
936+
do 25.times {
937937
fuzz_test(3);
938938
fuzz_test(16);
939939
fuzz_test(189);

src/libextra/flate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ mod tests {
9090
fn test_flate_round_trip() {
9191
let mut r = rand::rng();
9292
let mut words = ~[];
93-
for 20.times {
93+
do 20.times {
9494
let range = r.gen_uint_range(1, 10);
9595
words.push(r.gen_bytes(range));
9696
}
97-
for 20.times {
97+
do 20.times {
9898
let mut input = ~[];
99-
for 2000.times {
99+
do 2000.times {
100100
input.push_all(r.choose(words));
101101
}
102102
debug!("de/inflate of %u bytes of random word-sequences",

src/libextra/getopts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub mod groups {
662662
// here we just need to indent the start of the description
663663
let rowlen = row.len();
664664
if rowlen < 24 {
665-
for (24 - rowlen).times {
665+
do (24 - rowlen).times {
666666
row.push_char(' ')
667667
}
668668
} else {

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn escape_str(s: &str) -> ~str {
7777

7878
fn spaces(n: uint) -> ~str {
7979
let mut ss = ~"";
80-
for n.times {
80+
do n.times {
8181
ss.push_str(" ");
8282
}
8383
return ss;

src/libextra/ringbuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ mod tests {
509509
fn bench_grow(b: &mut test::BenchHarness) {
510510
let mut deq = RingBuf::new();
511511
do b.iter {
512-
for 65.times {
512+
do 65.times {
513513
deq.push_front(1);
514514
}
515515
}

0 commit comments

Comments
 (0)