rust/tests/ui/closures/issue-6801.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
421 B
Rust
Raw Normal View History

// Creating a stack closure which references a box and then
// transferring ownership of the box before invoking the stack
2013-05-27 14:21:45 -05:00
// closure results in a crash.
fn twice(x: Box<usize>) -> usize {
2013-05-27 14:21:45 -05:00
*x * 2
}
fn invoke<F>(f: F) where F: FnOnce() -> usize {
2013-05-27 14:21:45 -05:00
f();
}
fn main() {
let x : Box<usize> = Box::new(9);
let sq = || { *x * *x };
2013-05-27 14:21:45 -05:00
twice(x); //~ ERROR: cannot move out of
2013-05-27 14:21:45 -05:00
invoke(sq);
}