allow for loop bodies
This commit is contained in:
parent
653a1f8781
commit
79b3dedac3
2 changed files with 22 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
_ {}
|
||||
|
|
21
src/test/compile-fail/pure-loop-body.rs
Normal file
21
src/test/compile-fail/pure-loop-body.rs
Normal 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() {}
|
Loading…
Reference in a new issue