auto merge of #8216 : thestinger/rust/range, r=huonw
This commit is contained in:
commit
bbcce8d95c
117 changed files with 336 additions and 442 deletions
|
|
@ -17,7 +17,7 @@ pub mod kitties {
|
|||
}
|
||||
|
||||
impl cat {
|
||||
priv fn nap(&self) { for uint::range(1, 10000u) |_i|{}}
|
||||
priv fn nap(&self) {}
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -31,19 +31,19 @@ fn ascending<M: MutableMap<uint, uint>>(map: &mut M, n_keys: uint) {
|
|||
io::println(" Ascending integers:");
|
||||
|
||||
do timed("insert") {
|
||||
for uint::range(0, n_keys) |i| {
|
||||
foreach i in range(0u, n_keys) {
|
||||
map.insert(i, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
do timed("search") {
|
||||
for uint::range(0, n_keys) |i| {
|
||||
foreach i in range(0u, n_keys) {
|
||||
assert_eq!(map.find(&i).unwrap(), &(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
do timed("remove") {
|
||||
for uint::range(0, n_keys) |i| {
|
||||
foreach i in range(0, n_keys) {
|
||||
assert!(map.remove(&i));
|
||||
}
|
||||
}
|
||||
|
|
@ -74,19 +74,19 @@ fn descending<M: MutableMap<uint, uint>>(map: &mut M, n_keys: uint) {
|
|||
fn vector<M: MutableMap<uint, uint>>(map: &mut M, n_keys: uint, dist: &[uint]) {
|
||||
|
||||
do timed("insert") {
|
||||
for uint::range(0, n_keys) |i| {
|
||||
foreach i in range(0u, n_keys) {
|
||||
map.insert(dist[i], i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
do timed("search") {
|
||||
for uint::range(0, n_keys) |i| {
|
||||
foreach i in range(0u, n_keys) {
|
||||
assert_eq!(map.find(&dist[i]).unwrap(), &(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
do timed("remove") {
|
||||
for uint::range(0, n_keys) |i| {
|
||||
foreach i in range(0u, n_keys) {
|
||||
assert!(map.remove(&dist[i]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ impl Results {
|
|||
{
|
||||
let mut set = f();
|
||||
do timed(&mut self.sequential_ints) {
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
set.insert(i);
|
||||
}
|
||||
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
assert!(set.contains(&i));
|
||||
}
|
||||
}
|
||||
|
|
@ -67,12 +67,12 @@ impl Results {
|
|||
|
||||
{
|
||||
let mut set = f();
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
set.insert(i);
|
||||
}
|
||||
|
||||
do timed(&mut self.delete_ints) {
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
assert!(set.remove(&i));
|
||||
}
|
||||
}
|
||||
|
|
@ -88,12 +88,12 @@ impl Results {
|
|||
{
|
||||
let mut set = f();
|
||||
do timed(&mut self.sequential_strings) {
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
let s = uint::to_str(i);
|
||||
set.insert(s);
|
||||
}
|
||||
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
let s = uint::to_str(i);
|
||||
assert!(set.contains(&s));
|
||||
}
|
||||
|
|
@ -112,11 +112,11 @@ impl Results {
|
|||
|
||||
{
|
||||
let mut set = f();
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
set.insert(uint::to_str(i));
|
||||
}
|
||||
do timed(&mut self.delete_strings) {
|
||||
for uint::range(0, num_keys) |i| {
|
||||
foreach i in range(0u, num_keys) {
|
||||
assert!(set.remove(&uint::to_str(i)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ fn read_line() {
|
|||
let path = Path(env!("CFG_SRC_DIR"))
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
|
||||
for int::range(0, 3) |_i| {
|
||||
foreach _ in range(0, 3) {
|
||||
let reader = io::file_reader(&path).unwrap();
|
||||
while !reader.eof() {
|
||||
reader.read_line();
|
||||
|
|
@ -119,7 +119,7 @@ fn vec_push_all() {
|
|||
let mut r = rand::rng();
|
||||
|
||||
let mut v = ~[];
|
||||
for uint::range(0, 1500) |i| {
|
||||
foreach i in range(0u, 1500) {
|
||||
let mut rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
|
||||
if r.gen() {
|
||||
v.push_all(rv);
|
||||
|
|
@ -133,7 +133,7 @@ fn vec_push_all() {
|
|||
|
||||
fn is_utf8_ascii() {
|
||||
let mut v : ~[u8] = ~[];
|
||||
for uint::range(0, 20000) |_| {
|
||||
foreach _ in range(0u, 20000) {
|
||||
v.push('b' as u8);
|
||||
if !str::is_utf8(v) {
|
||||
fail!("is_utf8 failed");
|
||||
|
|
@ -144,7 +144,7 @@ fn is_utf8_ascii() {
|
|||
fn is_utf8_multibyte() {
|
||||
let s = "b¢€𤭢";
|
||||
let mut v : ~[u8]= ~[];
|
||||
for uint::range(0, 5000) |_| {
|
||||
foreach _ in range(0u, 5000) {
|
||||
v.push_all(s.as_bytes());
|
||||
if !str::is_utf8(v) {
|
||||
fail!("is_utf8 failed");
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn main() {
|
|||
|
||||
let n = uint::from_str(args[1]).get();
|
||||
|
||||
for uint::range(0u, n) |i| {
|
||||
foreach i in range(0u, n) {
|
||||
let x = uint::to_str(i);
|
||||
info!(x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,12 +64,12 @@ fn run(args: &[~str]) {
|
|||
let num_bytes = 100;
|
||||
let start = extra::time::precise_time_s();
|
||||
let mut worker_results = ~[];
|
||||
for uint::range(0, workers) |_i| {
|
||||
foreach _ in range(0u, workers) {
|
||||
let to_child = to_child.clone();
|
||||
let mut builder = task::task();
|
||||
builder.future_result(|r| worker_results.push(r));
|
||||
do builder.spawn {
|
||||
for uint::range(0, size / workers) |_i| {
|
||||
foreach _ in range(0u, size / workers) {
|
||||
//error!("worker %?: sending %? bytes", i, num_bytes);
|
||||
to_child.send(bytes(num_bytes));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,12 +58,12 @@ fn run(args: &[~str]) {
|
|||
let num_bytes = 100;
|
||||
let start = extra::time::precise_time_s();
|
||||
let mut worker_results = ~[];
|
||||
for uint::range(0, workers) |_i| {
|
||||
foreach _ in range(0u, workers) {
|
||||
let to_child = to_child.clone();
|
||||
let mut builder = task::task();
|
||||
builder.future_result(|r| worker_results.push(r));
|
||||
do builder.spawn {
|
||||
for uint::range(0, size / workers) |_i| {
|
||||
foreach _ in range(0u, size / workers) {
|
||||
//error!("worker %?: sending %? bytes", i, num_bytes);
|
||||
to_child.send(bytes(num_bytes));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
|
|||
let mut num_chan = Some(num_chan);
|
||||
let mut num_port = Some(num_port);
|
||||
// Send/Receive lots of messages.
|
||||
for uint::range(0u, count) |j| {
|
||||
foreach j in range(0u, count) {
|
||||
//error!("task %?, iter %?", i, j);
|
||||
let num_chan2 = num_chan.take_unwrap();
|
||||
let num_port2 = num_port.take_unwrap();
|
||||
|
|
@ -90,7 +90,7 @@ fn main() {
|
|||
// create the ring
|
||||
let mut futures = ~[];
|
||||
|
||||
for uint::range(1u, num_tasks) |i| {
|
||||
foreach i in range(1u, num_tasks) {
|
||||
//error!("spawning %?", i);
|
||||
let (new_chan, num_port) = init();
|
||||
let num_chan2 = Cell::new(num_chan.take());
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) {
|
|||
let mut num_chan = Some(num_chan);
|
||||
let mut num_port = Some(num_port);
|
||||
// Send/Receive lots of messages.
|
||||
for uint::range(0u, count) |j| {
|
||||
foreach j in range(0u, count) {
|
||||
//error!("task %?, iter %?", i, j);
|
||||
let num_chan2 = num_chan.take_unwrap();
|
||||
let num_port2 = num_port.take_unwrap();
|
||||
|
|
@ -86,7 +86,7 @@ fn main() {
|
|||
// create the ring
|
||||
let mut futures = ~[];
|
||||
|
||||
for uint::range(1u, num_tasks) |i| {
|
||||
foreach i in range(1u, num_tasks) {
|
||||
//error!("spawning %?", i);
|
||||
let (new_chan, num_port) = init();
|
||||
let num_chan2 = Cell::new(num_chan.take());
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ impl Noise2DContext {
|
|||
pub fn new() -> Noise2DContext {
|
||||
let mut r = rand::rng();
|
||||
let mut rgradients = [ Vec2 { x: 0.0, y: 0.0 }, ..256 ];
|
||||
for int::range(0, 256) |i| {
|
||||
foreach i in range(0, 256) {
|
||||
rgradients[i] = random_gradient(&mut r);
|
||||
}
|
||||
let mut permutations = [ 0, ..256 ];
|
||||
for int::range(0, 256) |i| {
|
||||
foreach i in range(0, 256) {
|
||||
permutations[i] = i;
|
||||
}
|
||||
r.shuffle_mut(permutations);
|
||||
|
|
@ -106,8 +106,8 @@ fn main() {
|
|||
let mut pixels = [0f32, ..256*256];
|
||||
let n2d = ~Noise2DContext::new();
|
||||
do 100.times {
|
||||
for int::range(0, 256) |y| {
|
||||
for int::range(0, 256) |x| {
|
||||
foreach y in range(0, 256) {
|
||||
foreach x in range(0, 256) {
|
||||
let v = n2d.get(
|
||||
x as f32 * 0.1f32,
|
||||
y as f32 * 0.1f32
|
||||
|
|
@ -117,8 +117,8 @@ fn main() {
|
|||
};
|
||||
};
|
||||
|
||||
for int::range(0, 256) |y| {
|
||||
for int::range(0, 256) |x| {
|
||||
foreach y in range(0, 256) {
|
||||
foreach x in range(0, 256) {
|
||||
print(symbols[pixels[y*256+x] / 0.2f32 as int]);
|
||||
}
|
||||
println("");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use std::from_str::FromStr;
|
||||
use std::i32::range;
|
||||
use std::os;
|
||||
use std::vec::MutableVector;
|
||||
use std::vec;
|
||||
|
|
@ -42,7 +41,7 @@ fn fannkuch_redux(n: i32) -> i32 {
|
|||
}
|
||||
|
||||
let k2 = (k+1) >> 1;
|
||||
for range(0, k2) |i| {
|
||||
foreach i in range(0i32, k2) {
|
||||
let (perm_i, perm_k_i) = {
|
||||
(perm.unsafe_get(i as uint),
|
||||
perm.unsafe_get((k-i) as uint))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::cast::transmute;
|
|||
use std::from_str::FromStr;
|
||||
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
|
||||
use std::os;
|
||||
use std::uint::{min, range};
|
||||
use std::uint::min;
|
||||
use std::vec::bytes::copy_memory;
|
||||
use std::vec;
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ impl RandomFasta {
|
|||
let mut buf = [0, ..LINE_LEN + 1];
|
||||
|
||||
do lines.times {
|
||||
for range(0, LINE_LEN) |i| {
|
||||
foreach i in range(0u, LINE_LEN) {
|
||||
buf[i] = self.nextc();
|
||||
}
|
||||
buf[LINE_LEN] = '\n' as u8;
|
||||
|
|
@ -174,7 +174,7 @@ impl RandomFasta {
|
|||
1,
|
||||
self.stdout);
|
||||
}
|
||||
for range(0, chars_left) |i| {
|
||||
foreach i in range(0u, chars_left) {
|
||||
buf[i] = self.nextc();
|
||||
}
|
||||
fwrite(transmute(&buf[0]), chars_left as size_t, 1, self.stdout);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ fn make_random_fasta(wr: @io::Writer,
|
|||
last: rng.next()
|
||||
};
|
||||
let mut op: ~str = ~"";
|
||||
for uint::range(0u, n as uint) |_i| {
|
||||
foreach _ in range(0u, n as uint) {
|
||||
op.push_char(select_random(myrandom_next(rng, 100u32),
|
||||
genelist.clone()));
|
||||
if op.len() >= LINE_LENGTH {
|
||||
|
|
@ -96,7 +96,7 @@ fn make_repeat_fasta(wr: @io::Writer, id: ~str, desc: ~str, s: ~str, n: int) {
|
|||
wr.write_line(~">" + id + " " + desc);
|
||||
let mut op = str::with_capacity( LINE_LENGTH );
|
||||
let sl = s.len();
|
||||
for uint::range(0u, n as uint) |i| {
|
||||
foreach i in range(0u, n as uint) {
|
||||
if (op.len() >= LINE_LENGTH) {
|
||||
wr.write_line( op );
|
||||
op = str::with_capacity( LINE_LENGTH );
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl Code {
|
|||
|
||||
fn pack(string: &str) -> Code {
|
||||
let mut code = Code(0u64);
|
||||
for uint::range(0, string.len()) |i| {
|
||||
foreach i in range(0u, string.len()) {
|
||||
code = code.push_char(string[i]);
|
||||
}
|
||||
code
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use std::cast::transmute;
|
||||
use std::from_str::FromStr;
|
||||
use std::i32::range;
|
||||
use std::libc::{STDOUT_FILENO, c_int, fdopen, fputc};
|
||||
use std::os;
|
||||
|
||||
|
|
@ -20,9 +19,9 @@ fn main() {
|
|||
let mode = "w";
|
||||
let stdout = fdopen(STDOUT_FILENO as c_int, transmute(&mode[0]));
|
||||
|
||||
for range(0, h) |y| {
|
||||
foreach y in range(0i32, h) {
|
||||
let y = y as f64;
|
||||
for range(0, w) |x| {
|
||||
foreach x in range(0i32, w) {
|
||||
let mut Zr = 0f64;
|
||||
let mut Zi = 0f64;
|
||||
let mut Tr = 0f64;
|
||||
|
|
@ -30,7 +29,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 range(0, ITER as i32) |_| {
|
||||
foreach _ in range(0i32, ITER as i32) {
|
||||
if Tr + Ti > LIMIT * LIMIT {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use std::from_str::FromStr;
|
||||
use std::os;
|
||||
use std::uint::range;
|
||||
|
||||
static PI: f64 = 3.141592653589793;
|
||||
static SOLAR_MASS: f64 = 4.0 * PI * PI;
|
||||
|
|
@ -81,8 +80,8 @@ struct Planet {
|
|||
fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
|
||||
let mut d = [ 0.0, ..3 ];
|
||||
do (steps as uint).times {
|
||||
for range(0, N_BODIES) |i| {
|
||||
for range(i + 1, N_BODIES) |j| {
|
||||
foreach i in range(0u, N_BODIES) {
|
||||
foreach j in range(i + 1, N_BODIES) {
|
||||
d[0] = bodies[i].x[0] - bodies[j].x[0];
|
||||
d[1] = bodies[i].x[1] - bodies[j].x[1];
|
||||
d[2] = bodies[i].x[2] - bodies[j].x[2];
|
||||
|
|
@ -113,13 +112,13 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
|
|||
fn energy(bodies: &[Planet, ..N_BODIES]) -> f64 {
|
||||
let mut e = 0.0;
|
||||
let mut d = [ 0.0, ..3 ];
|
||||
for range(0, N_BODIES) |i| {
|
||||
for range(0, 3) |k| {
|
||||
foreach i in range(0u, N_BODIES) {
|
||||
foreach k in range(0u, 3) {
|
||||
e += bodies[i].mass * bodies[i].v[k] * bodies[i].v[k] / 2.0;
|
||||
}
|
||||
|
||||
for range(i + 1, N_BODIES) |j| {
|
||||
for range(0, 3) |k| {
|
||||
foreach j in range(i + 1, N_BODIES) {
|
||||
foreach k in range(0u, 3) {
|
||||
d[k] = bodies[i].x[k] - bodies[j].x[k];
|
||||
}
|
||||
let dist = (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]).sqrt();
|
||||
|
|
@ -130,8 +129,8 @@ fn energy(bodies: &[Planet, ..N_BODIES]) -> f64 {
|
|||
}
|
||||
|
||||
fn offset_momentum(bodies: &mut [Planet, ..N_BODIES]) {
|
||||
for range(0, N_BODIES) |i| {
|
||||
for range(0, 3) |k| {
|
||||
foreach i in range(0u, N_BODIES) {
|
||||
foreach k in range(0u, 3) {
|
||||
bodies[0].v[k] -= bodies[i].v[k] * bodies[i].mass / SOLAR_MASS;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ extern mod extra;
|
|||
|
||||
use extra::{time, getopts};
|
||||
use std::comm::*;
|
||||
use std::int::range;
|
||||
use std::io::WriterUtil;
|
||||
use std::io;
|
||||
use std::os;
|
||||
|
|
@ -84,7 +83,7 @@ fn stress_task(id: int) {
|
|||
|
||||
fn stress(num_tasks: int) {
|
||||
let mut results = ~[];
|
||||
for range(0, num_tasks) |i| {
|
||||
foreach i in range(0, num_tasks) {
|
||||
let mut builder = task::task();
|
||||
builder.future_result(|r| results.push(r));
|
||||
do builder.spawn {
|
||||
|
|
@ -117,8 +116,8 @@ fn main() {
|
|||
|
||||
let out = io::stdout();
|
||||
|
||||
for range(1, max + 1) |n| {
|
||||
for range(0, num_trials) |_i| {
|
||||
foreach n in range(1, max + 1) {
|
||||
foreach _ in range(0, num_trials) {
|
||||
let start = time::precise_time_ns();
|
||||
let fibn = fib(n);
|
||||
let stop = time::precise_time_ns();
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ use std::os;
|
|||
use std::uint;
|
||||
|
||||
fn append_sequential(min: uint, max: uint, map: &mut SmallIntMap<uint>) {
|
||||
for uint::range(min, max) |i| {
|
||||
foreach i in range(min, max) {
|
||||
map.insert(i, i + 22u);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_sequential(min: uint, max: uint, map: &SmallIntMap<uint>) {
|
||||
for uint::range(min, max) |i| {
|
||||
foreach i in range(min, max) {
|
||||
assert_eq!(*map.get(&i), i + 22u);
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ fn main() {
|
|||
let mut checkf = 0.0;
|
||||
let mut appendf = 0.0;
|
||||
|
||||
for uint::range(0u, rep) |_r| {
|
||||
foreach _ in range(0u, rep) {
|
||||
let mut map = SmallIntMap::new();
|
||||
let start = extra::time::precise_time_s();
|
||||
append_sequential(0u, max, &mut map);
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ impl Sudoku {
|
|||
}
|
||||
|
||||
pub fn equal(&self, other: &Sudoku) -> bool {
|
||||
for u8::range(0u8, 9u8) |row| {
|
||||
for u8::range(0u8, 9u8) |col| {
|
||||
foreach row in range(0u8, 9u8) {
|
||||
foreach col in range(0u8, 9u8) {
|
||||
if self.grid[row][col] != other.grid[row][col] {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -87,9 +87,9 @@ impl Sudoku {
|
|||
}
|
||||
|
||||
pub fn write(&self, writer: @io::Writer) {
|
||||
for u8::range(0u8, 9u8) |row| {
|
||||
foreach row in range(0u8, 9u8) {
|
||||
writer.write_str(fmt!("%u", self.grid[row][0] as uint));
|
||||
for u8::range(1u8, 9u8) |col| {
|
||||
foreach col in range(1u8, 9u8) {
|
||||
writer.write_str(fmt!(" %u", self.grid[row][col] as uint));
|
||||
}
|
||||
writer.write_char('\n');
|
||||
|
|
@ -99,8 +99,8 @@ impl Sudoku {
|
|||
// solve sudoku grid
|
||||
pub fn solve(&mut self) {
|
||||
let mut work: ~[(u8, u8)] = ~[]; /* queue of uncolored fields */
|
||||
for u8::range(0u8, 9u8) |row| {
|
||||
for u8::range(0u8, 9u8) |col| {
|
||||
foreach row in range(0u8, 9u8) {
|
||||
foreach col in range(0u8, 9u8) {
|
||||
let color = self.grid[row][col];
|
||||
if color == 0u8 {
|
||||
work.push((row, col));
|
||||
|
|
@ -143,7 +143,7 @@ impl Sudoku {
|
|||
|
||||
// find colors available in neighbourhood of (row, col)
|
||||
fn drop_colors(&mut self, avail: &mut Colors, row: u8, col: u8) {
|
||||
for u8::range(0u8, 9u8) |idx| {
|
||||
foreach idx in range(0u8, 9u8) {
|
||||
avail.remove(self.grid[idx][col]); /* check same column fields */
|
||||
avail.remove(self.grid[row][idx]); /* check same row fields */
|
||||
}
|
||||
|
|
@ -151,8 +151,10 @@ impl Sudoku {
|
|||
// check same block fields
|
||||
let row0 = (row / 3u8) * 3u8;
|
||||
let col0 = (col / 3u8) * 3u8;
|
||||
for u8::range(row0, row0 + 3u8) |alt_row| {
|
||||
for u8::range(col0, col0 + 3u8) |alt_col| { avail.remove(self.grid[alt_row][alt_col]); }
|
||||
foreach alt_row in range(row0, row0 + 3u8) {
|
||||
foreach alt_col in range(col0, col0 + 3u8) {
|
||||
avail.remove(self.grid[alt_row][alt_col]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +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.
|
||||
|
||||
use std::uint;
|
||||
|
||||
fn not_bool(f: &fn(int) -> ~str) -> bool {}
|
||||
|
||||
fn main() {
|
||||
for uint::range(0, 100000) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
false
|
||||
};
|
||||
for not_bool |_i| {
|
||||
//~^ ERROR A `for` loop iterator should expect a closure that returns `bool`
|
||||
~"hi"
|
||||
};
|
||||
for uint::range(0, 100000) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
~"hi"
|
||||
};
|
||||
for not_bool() |_i| {
|
||||
//~^ ERROR A `for` loop iterator should expect a closure that returns `bool`
|
||||
};
|
||||
}
|
||||
|
|
@ -17,11 +17,11 @@ fn to_str(u: uint) -> ~str { fail!(); }
|
|||
fn uuid_random() -> uint { fail!(); }
|
||||
|
||||
fn main() {
|
||||
do uint::range(0, 100000) |_i| { //~ ERROR Do-block body must return bool, but
|
||||
do range(0u, 100000).advance |_i| { //~ ERROR Do-block body must return bool, but
|
||||
};
|
||||
// should get a more general message if the callback
|
||||
// doesn't return nil
|
||||
do uint::range(0, 100000) |_i| { //~ ERROR mismatched types
|
||||
do range(0u, 100000).advance |_i| { //~ ERROR mismatched types
|
||||
~"str"
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,5 @@ fn test(_x: ~uint) {}
|
|||
|
||||
fn main() {
|
||||
let i = ~3;
|
||||
for uint::range(0, 10) |_x| {
|
||||
test(i); //~ ERROR cannot move out
|
||||
}
|
||||
let _f = || test(i); //~ ERROR cannot move out
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
// error-pattern:method `nap` is private
|
||||
|
||||
mod kitties {
|
||||
use std::uint;
|
||||
|
||||
pub struct cat {
|
||||
priv meows : uint,
|
||||
|
||||
|
|
@ -20,7 +18,7 @@ mod kitties {
|
|||
}
|
||||
|
||||
impl cat {
|
||||
priv fn nap(&self) { uint::range(1u, 10000u, |_i| false); }
|
||||
priv fn nap(&self) {}
|
||||
}
|
||||
|
||||
pub fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ struct dog {
|
|||
|
||||
impl dog {
|
||||
pub fn chase_cat(&mut self) {
|
||||
for uint::range(0u, 10u) |_i| {
|
||||
let _f = || {
|
||||
let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
|
||||
*p = 3u;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,4 @@
|
|||
// error-pattern:moop
|
||||
extern mod extra;
|
||||
|
||||
use std::uint;
|
||||
|
||||
fn main() { for uint::range(0u, 10u) |_i| { fail!("moop"); } }
|
||||
fn main() { foreach _ in range(0u, 10u) { fail!("moop"); } }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
let count = @mut 0u;
|
||||
let mut map = std::hashmap::HashMap::new();
|
||||
let mut arr = ~[];
|
||||
for std::uint::range(0u, 10u) |i| {
|
||||
foreach i in range(0u, 10u) {
|
||||
arr.push(@~"key stuff");
|
||||
map.insert(arr.clone(), arr + &[@~"value stuff"]);
|
||||
if arr.len() == 5 {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn add_int(x: &mut Ints, v: int) {
|
|||
|
||||
fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) -> bool {
|
||||
let l = x.values.len();
|
||||
uint::range(0, l, |i| f(&x.values[i]))
|
||||
range(0u, l).advance(|i| f(&x.values[i]))
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
|||
|
||||
|
||||
fn annoy_neighbors(critter: @noisy) {
|
||||
for uint::range(0u, 10u) |i| { critter.speak(); }
|
||||
foreach i in range(0u, 10) { critter.speak(); }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class cat : map<int, bool> {
|
|||
|
||||
pub fn main() {
|
||||
let nyan : cat = cat(0, 2, "nyan");
|
||||
for uint::range(1u, 5u) |_i| { nyan.speak(); }
|
||||
foreach _ in range(1u, 5u) { nyan.speak(); }
|
||||
// cat returns true if uint input is greater than
|
||||
// the number of meows so far
|
||||
assert!((nyan.get(1)));
|
||||
|
|
|
|||
|
|
@ -117,11 +117,11 @@ impl<T> cat<T> {
|
|||
|
||||
pub fn main() {
|
||||
let mut nyan: cat<~str> = cat::new(0, 2, ~"nyan");
|
||||
for uint::range(1, 5) |_| { nyan.speak(); }
|
||||
foreach _ in range(1u, 5) { nyan.speak(); }
|
||||
assert!(*nyan.find(&1).unwrap() == ~"nyan");
|
||||
assert_eq!(nyan.find(&10), None);
|
||||
let mut spotty: cat<cat_type> = cat::new(2, 57, tuxedo);
|
||||
for uint::range(0, 6) |_| { spotty.speak(); }
|
||||
foreach _ in range(0u, 6) { spotty.speak(); }
|
||||
assert_eq!(spotty.len(), 8);
|
||||
assert!((spotty.contains_key(&2)));
|
||||
assert_eq!(spotty.get(&3), &tuxedo);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,6 @@ pub fn main() {
|
|||
let mut nyan = cat(0u, 2, ~"nyan");
|
||||
nyan.eat();
|
||||
assert!((!nyan.eat()));
|
||||
for uint::range(1u, 10u) |_i| { nyan.speak(); };
|
||||
foreach _ in range(1u, 10u) { nyan.speak(); };
|
||||
assert!((nyan.eat()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
use std::uint;
|
||||
|
||||
trait noisy {
|
||||
fn speak(&mut self);
|
||||
fn speak(&mut self);
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
|
|
@ -48,7 +48,7 @@ impl cat {
|
|||
}
|
||||
|
||||
impl noisy for cat {
|
||||
fn speak(&mut self) { self.meow(); }
|
||||
fn speak(&mut self) { self.meow(); }
|
||||
}
|
||||
|
||||
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
|
||||
|
|
@ -65,10 +65,10 @@ fn make_speak<C:noisy>(mut c: C) {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut nyan = cat(0u, 2, ~"nyan");
|
||||
nyan.eat();
|
||||
assert!((!nyan.eat()));
|
||||
for uint::range(1u, 10u) |_i| {
|
||||
make_speak(nyan.clone());
|
||||
}
|
||||
let mut nyan = cat(0u, 2, ~"nyan");
|
||||
nyan.eat();
|
||||
assert!((!nyan.eat()));
|
||||
foreach _ in range(1u, 10u) {
|
||||
make_speak(nyan.clone());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class cat : noisy, scratchy, bitey {
|
|||
}
|
||||
|
||||
fn annoy_neighbors<T:noisy>(critter: T) {
|
||||
for uint::range(0u, 10u) |i| {
|
||||
foreach i in range(0u, 10u) {
|
||||
let what = critter.speak();
|
||||
info!("%u %d", i, what);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ pub fn main() {
|
|||
let mut nyan = cat(0u, 2, ~"nyan");
|
||||
nyan.eat();
|
||||
assert!((!nyan.eat()));
|
||||
for uint::range(1u, 10u) |_i| { nyan.speak(); };
|
||||
foreach _ in range(1u, 10u) { nyan.speak(); };
|
||||
assert!((nyan.eat()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::uint;
|
||||
|
||||
struct cat {
|
||||
priv meows : uint,
|
||||
|
||||
|
|
@ -54,6 +52,6 @@ pub fn main() {
|
|||
let mut nyan = cat(0u, 2, ~"nyan");
|
||||
nyan.eat();
|
||||
assert!((!nyan.eat()));
|
||||
for uint::range(1u, 10u) |_i| { nyan.speak(); };
|
||||
foreach _ in range(1u, 10u) { nyan.speak(); };
|
||||
assert!((nyan.eat()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
extern mod extra;
|
||||
|
||||
use std::io;
|
||||
use std::uint;
|
||||
use std::vec;
|
||||
|
||||
trait methods {
|
||||
|
|
@ -41,7 +40,7 @@ pub fn main() {
|
|||
let bools = ~[false, false, true, false, false, true, true, false];
|
||||
let bools2 = to_bools(Storage{storage: ~[0b01100100]});
|
||||
|
||||
for uint::range(0, 8) |i| {
|
||||
foreach i in range(0u, 8) {
|
||||
printfln!("%u => %u vs %u", i, bools[i] as uint, bools2[i] as uint);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,13 +134,13 @@ impl Canvas for AsciiArt {
|
|||
|
||||
fn add_rect(&mut self, shape: Rect) {
|
||||
// Add the top and bottom lines.
|
||||
for int::range(shape.top_left.x, shape.top_left.x + shape.size.width) |x| {
|
||||
foreach x in range(shape.top_left.x, shape.top_left.x + shape.size.width) {
|
||||
self.add_pt(x, shape.top_left.y);
|
||||
self.add_pt(x, shape.top_left.y + shape.size.height - 1);
|
||||
}
|
||||
|
||||
// Add the left and right lines.
|
||||
for int::range(shape.top_left.y, shape.top_left.y + shape.size.height) |y|{
|
||||
foreach y in range(shape.top_left.y, shape.top_left.y + shape.size.height) {
|
||||
self.add_pt(shape.top_left.x, y);
|
||||
self.add_pt(shape.top_left.x + shape.size.width - 1, y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ extern mod extra;
|
|||
|
||||
use std::comm::Chan;
|
||||
use std::task;
|
||||
use std::uint;
|
||||
|
||||
type RingBuffer = ~[float];
|
||||
type SamplesFn = ~fn(samples: &RingBuffer);
|
||||
|
|
@ -18,8 +17,9 @@ fn foo(name: ~str, samples_chan: Chan<Msg>) {
|
|||
let callback: SamplesFn =
|
||||
|buffer|
|
||||
{
|
||||
for uint::range(0, buffer.len())
|
||||
|i| {error!("%?: %f", i, buffer[i])}
|
||||
foreach i in range(0u, buffer.len()) {
|
||||
error!("%?: %f", i, buffer[i])
|
||||
}
|
||||
};
|
||||
samples_chan.send(GetSamples(name.clone(), callback));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
|
||||
|
||||
fn range(a: int, b: int, it: &fn(int)) {
|
||||
fn range_(a: int, b: int, it: &fn(int)) {
|
||||
assert!((a < b));
|
||||
let mut i: int = a;
|
||||
while i < b { it(i); i += 1; }
|
||||
|
|
@ -18,6 +18,6 @@ fn range(a: int, b: int, it: &fn(int)) {
|
|||
|
||||
pub fn main() {
|
||||
let mut sum: int = 0;
|
||||
range(0, 100, |x| sum += x );
|
||||
range_(0, 100, |x| sum += x );
|
||||
info!(sum);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
extern mod extra;
|
||||
|
||||
use std::task;
|
||||
use std::uint;
|
||||
|
||||
fn die() {
|
||||
fail!();
|
||||
|
|
@ -23,7 +22,7 @@ fn iloop() {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
for uint::range(0u, 100u) |_i| {
|
||||
foreach _ in range(0u, 100u) {
|
||||
task::spawn_unlinked(|| iloop() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
extern mod extra;
|
||||
|
||||
use std::uint;
|
||||
|
||||
#[deriving(Clone)]
|
||||
struct Triple {
|
||||
x: int,
|
||||
|
|
@ -28,7 +26,7 @@ fn test(x: bool, foo: ~Triple) -> int {
|
|||
|
||||
pub fn main() {
|
||||
let x = ~Triple{x: 1, y: 2, z: 3};
|
||||
for uint::range(0u, 10000u) |_i| {
|
||||
foreach _ in range(0u, 10000u) {
|
||||
assert_eq!(test(true, x.clone()), 2);
|
||||
}
|
||||
assert_eq!(test(false, x), 5);
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
extern mod extra;
|
||||
|
||||
use std::uint;
|
||||
|
||||
struct Triple { x: int, y: int, z: int }
|
||||
|
||||
fn test(x: bool, foo: @Triple) -> int {
|
||||
|
|
@ -23,7 +21,7 @@ fn test(x: bool, foo: @Triple) -> int {
|
|||
|
||||
pub fn main() {
|
||||
let x = @Triple{x: 1, y: 2, z: 3};
|
||||
for uint::range(0u, 10000u) |i| {
|
||||
foreach i in range(0u, 10000u) {
|
||||
assert_eq!(test(true, x), 2);
|
||||
}
|
||||
assert_eq!(test(false, x), 5);
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ use std::int;
|
|||
use std::uint;
|
||||
|
||||
fn uint_range(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
|
||||
uint::range(lo, hi, it)
|
||||
range(lo, hi).advance(it)
|
||||
}
|
||||
|
||||
fn int_range(lo: int, hi: int, it: &fn(int) -> bool) -> bool {
|
||||
int::range(lo, hi, it)
|
||||
range(lo, hi).advance(it)
|
||||
}
|
||||
|
||||
fn uint_range_rev(hi: uint, lo: uint, it: &fn(uint) -> bool) -> bool {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ use std::int;
|
|||
use std::uint;
|
||||
|
||||
fn uint_range(lo: uint, hi: uint, it: &fn(uint) -> bool) -> bool {
|
||||
uint::range(lo, hi, it)
|
||||
range(lo, hi).advance(it)
|
||||
}
|
||||
|
||||
fn int_range(lo: int, hi: int, it: &fn(int) -> bool) -> bool {
|
||||
int::range(lo, hi, it)
|
||||
range(lo, hi).advance(it)
|
||||
}
|
||||
|
||||
fn int_range_step(a: int, b: int, step: int, it: &fn(int) -> bool) -> bool {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::uint::{range};
|
||||
|
||||
trait FooTrait {
|
||||
fn foo(&self) -> uint;
|
||||
}
|
||||
|
|
@ -31,7 +29,7 @@ pub fn main() {
|
|||
~BarStruct{ x: 2 } as ~FooTrait
|
||||
];
|
||||
|
||||
for range(0, foos.len()) |i| {
|
||||
foreach i in range(0u, foos.len()) {
|
||||
assert_eq!(i, foos[i].foo());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::sys;
|
||||
use std::uint;
|
||||
|
||||
#[packed]
|
||||
#[deriving(Eq)]
|
||||
|
|
@ -23,7 +22,7 @@ fn main() {
|
|||
|
||||
assert_eq!(sys::size_of::<[Foo, .. 10]>(), 90);
|
||||
|
||||
for uint::range(0, 10) |i| {
|
||||
foreach i in range(0u, 10) {
|
||||
assert_eq!(foos[i], Foo { bar: 1, baz: 2});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,11 @@
|
|||
// pattern-bound var is an upvar (when translating
|
||||
// the for-each body)
|
||||
|
||||
use std::uint;
|
||||
|
||||
fn foo(src: uint) {
|
||||
|
||||
match Some(src) {
|
||||
Some(src_id) => {
|
||||
for uint::range(0u, 10u) |i| {
|
||||
foreach i in range(0u, 10u) {
|
||||
let yyy = src_id;
|
||||
assert_eq!(yyy, 0u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::uint;
|
||||
|
||||
struct cat {
|
||||
priv meows : uint,
|
||||
|
||||
|
|
@ -24,7 +22,7 @@ impl cat {
|
|||
}
|
||||
|
||||
impl cat {
|
||||
fn nap(&mut self) { for uint::range(1u, 10u) |_i| { }}
|
||||
fn nap(&mut self) { foreach _ in range(1u, 10u) { } }
|
||||
}
|
||||
|
||||
fn cat(in_x : uint, in_y : int) -> cat {
|
||||
|
|
|
|||
|
|
@ -8,13 +8,12 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::uint;
|
||||
use std::util;
|
||||
|
||||
pub fn main() {
|
||||
let mut x = 4;
|
||||
|
||||
for uint::range(0, 3) |i| {
|
||||
foreach i in range(0u, 3) {
|
||||
// ensure that the borrow in this alt
|
||||
// does not inferfere with the swap
|
||||
// below. note that it would it you
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ extern mod extra;
|
|||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
use std::uint;
|
||||
|
||||
fn die() {
|
||||
fail!();
|
||||
|
|
@ -34,7 +33,7 @@ fn iloop() {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
for uint::range(0u, 16u) |_i| {
|
||||
foreach _ in range(0u, 16u) {
|
||||
task::spawn_unlinked(|| iloop() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub fn main() {
|
|||
match io::file_writer(&path, [io::Create, io::Truncate]) {
|
||||
Err(ref e) => fail!(e.clone()),
|
||||
Ok(f) => {
|
||||
for uint::range(0, 1000) |_i| {
|
||||
foreach _ in range(0u, 1000) {
|
||||
f.write_u8(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ trait map<T> {
|
|||
impl<T> map<T> for ~[T] {
|
||||
fn map<U>(&self, f: &fn(&T) -> U) -> ~[U] {
|
||||
let mut r = ~[];
|
||||
// FIXME: #7355 generates bad code with Iterator
|
||||
for std::uint::range(0, self.len()) |i| {
|
||||
// FIXME: #7355 generates bad code with VecIterator
|
||||
foreach i in range(0u, self.len()) {
|
||||
r.push(f(&self[i]));
|
||||
}
|
||||
r
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ struct S<T> {
|
|||
b: uint,
|
||||
}
|
||||
|
||||
fn range(lo: uint, hi: uint, it: &fn(uint)) {
|
||||
fn range_(lo: uint, hi: uint, it: &fn(uint)) {
|
||||
let mut lo_ = lo;
|
||||
while lo_ < hi { it(lo_); lo_ += 1u; }
|
||||
}
|
||||
|
||||
fn create_index<T>(index: ~[S<T>], hash_fn: extern fn(T) -> uint) {
|
||||
range(0u, 256u, |_i| { let bucket: ~[T] = ~[]; } )
|
||||
range_(0u, 256u, |_i| { let bucket: ~[T] = ~[]; } )
|
||||
}
|
||||
|
||||
pub fn main() { }
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
use std::comm::*;
|
||||
use std::task;
|
||||
use std::uint;
|
||||
|
||||
fn child(c: &SharedChan<~uint>, i: uint) {
|
||||
c.send(~i);
|
||||
|
|
@ -21,14 +20,14 @@ pub fn main() {
|
|||
let ch = SharedChan::new(ch);
|
||||
let n = 100u;
|
||||
let mut expected = 0u;
|
||||
for uint::range(0u, n) |i| {
|
||||
foreach i in range(0u, n) {
|
||||
let ch = ch.clone();
|
||||
task::spawn(|| child(&ch, i) );
|
||||
expected += i;
|
||||
}
|
||||
|
||||
let mut actual = 0u;
|
||||
for uint::range(0u, n) |_i| {
|
||||
foreach _ in range(0u, n) {
|
||||
let j = p.recv();
|
||||
actual += *j;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue