rust/src/test/compile-fail/pure-loop-body.rs
2012-08-01 19:16:06 -07:00

22 lines
493 B
Rust

pure fn range(from: uint, to: uint, f: fn(uint) -> bool) {
let mut i = from;
while i < to {
if !f(i) {return;} // Note: legal to call argument, even if it is not pure.
i += 1u;
}
}
pure fn range2(from: uint, to: uint, f: fn(uint)) {
for range(from, to) |i| {
f(i*2u);
}
}
pure fn range3(from: uint, to: uint, f: {x: fn(uint)}) {
for range(from, to) |i| {
f.x(i*2u); //~ ERROR access to impure function prohibited
}
}
fn main() {}