Skip to content

Commit 79b3ded

Browse files
committed
allow for loop bodies
1 parent 653a1f8 commit 79b3ded

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/rustc/middle/borrowck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl methods for check_loan_ctxt {
654654
self.fn_args.contains(did.node);
655655
if is_fn_arg { ret; } // case (a) above
656656
}
657-
ast::expr_fn_block(*) | ast::expr_fn(*) {
657+
ast::expr_fn_block(*) | ast::expr_fn(*) | ast::expr_loop_body(*) {
658658
if self.is_stack_closure(expr.id) { ret; } // case (b) above
659659
}
660660
_ {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
pure fn range(from: uint, to: uint, f: fn(uint) -> bool) {
2+
let mut i = from;
3+
while i < to {
4+
if !f(i) {ret;} // Note: legal to call argument, even if it is not pure.
5+
i += 1u;
6+
}
7+
}
8+
9+
pure fn range2(from: uint, to: uint, f: fn(uint)) {
10+
for range(from, to) { |i|
11+
f(i*2u);
12+
}
13+
}
14+
15+
pure fn range3(from: uint, to: uint, f: {x: fn(uint)}) {
16+
for range(from, to) { |i|
17+
f.x(i*2u); //! ERROR access to impure function prohibited
18+
}
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)