allow for loop bodies

This commit is contained in:
Niko Matsakis 2012-05-25 00:39:25 -07:00
parent 653a1f8781
commit 79b3dedac3
2 changed files with 22 additions and 1 deletions

View file

@ -654,7 +654,7 @@ impl methods for check_loan_ctxt {
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
}
_ {}

View file

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