rust/src/test/compile-fail/lambda-mutate-nested.rs

16 lines
387 B
Rust
Raw Normal View History

2012-05-10 21:58:23 -05:00
// error-pattern:assigning to immutable upvar
// Make sure that nesting a block within a fn@ doesn't let us
// mutate upvars from a fn@.
2012-01-23 16:59:00 -06:00
fn f2(x: fn()) { x(); }
fn main() {
let i = 0;
let ctr = fn@ () -> int { f2({|| i = i + 1; }); ret i; };
log(error, ctr());
log(error, ctr());
log(error, ctr());
log(error, ctr());
log(error, ctr());
log(error, i);
}