PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/graydon/rust
Rust | 15 lines | 11 code | 1 blank | 3 comment | 0 complexity | 5f6dfb9a7800483dccde262f26d3cdb8 MD5 | raw file
  1. // error-pattern:assigning to captured outer immutable variable in a stack closure
  2. // Make sure that nesting a block within a fn@ doesn't let us
  3. // mutate upvars from a fn@.
  4. fn f2(x: fn()) { x(); }
  5. fn main() {
  6. let i = 0;
  7. let ctr = fn@ () -> int { f2(|| i = i + 1 ); return i; };
  8. log(error, ctr());
  9. log(error, ctr());
  10. log(error, ctr());
  11. log(error, ctr());
  12. log(error, ctr());
  13. log(error, i);
  14. }