]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/issue-6801.rs
Rollup merge of #106625 - Swatinem:ref/cov6, r=nagisa
[rust.git] / tests / ui / closures / issue-6801.rs
1 // Creating a stack closure which references a box and then
2 // transferring ownership of the box before invoking the stack
3 // closure results in a crash.
4
5
6
7 fn twice(x: Box<usize>) -> usize {
8      *x * 2
9 }
10
11 fn invoke<F>(f: F) where F: FnOnce() -> usize {
12      f();
13 }
14
15 fn main() {
16       let x  : Box<usize>  = Box::new(9);
17       let sq =  || { *x * *x };
18
19       twice(x); //~ ERROR: cannot move out of
20       invoke(sq);
21 }