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

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 19:21:45 +00:00
// closure results in a crash.
fn twice(x: Box<usize>) -> usize {
2013-05-27 19:21:45 +00:00
*x * 2
}
fn invoke<F>(f: F) where F: FnOnce() -> usize {
2013-05-27 19:21:45 +00:00
f();
}
fn main() {
let x : Box<usize> = Box::new(9);
let sq = || { *x * *x };
2013-05-27 19:21:45 +00:00
twice(x); //~ ERROR: cannot move out of
2013-05-27 19:21:45 +00:00
invoke(sq);
}