mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
allow for loop bodies
This commit is contained in:
@@ -654,7 +654,7 @@ fn check_pure_callee_or_arg(pc: purity_cause, expr: @ast::expr) {
|
||||
self.fn_args.contains(did.node);
|
||||
if is_fn_arg { ret; } // case (a) above
|
||||
}
|
||||
ast::expr_fn_block(*) | ast::expr_fn(*) {
|
||||
ast::expr_fn_block(*) | ast::expr_fn(*) | ast::expr_loop_body(*) {
|
||||
if self.is_stack_closure(expr.id) { ret; } // case (b) above
|
||||
}
|
||||
_ {}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
pure fn range(from: uint, to: uint, f: fn(uint) -> bool) {
|
||||
let mut i = from;
|
||||
while i < to {
|
||||
if !f(i) {ret;} // 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() {}
|
||||
Reference in New Issue
Block a user