]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unboxed-closures/unboxed-closure-illegal-move.rs
Sync rust-lang/portable-simd@5f49d4c8435a25d804b2f375e949cb25479f5be9
[rust.git] / src / test / ui / unboxed-closures / unboxed-closure-illegal-move.rs
1 #![feature(unboxed_closures)]
2
3 // Tests that we can't move out of an unboxed closure environment
4 // if the upvar is captured by ref or the closure takes self by
5 // reference.
6
7 fn to_fn<A,F:Fn<A>>(f: F) -> F { f }
8 fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
9 fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
10
11 fn main() {
12     // By-ref cases
13     {
14         let x = Box::new(0);
15         let f = to_fn(|| drop(x)); //~ ERROR cannot move
16     }
17     {
18         let x = Box::new(0);
19         let f = to_fn_mut(|| drop(x)); //~ ERROR cannot move
20     }
21     {
22         let x = Box::new(0);
23         let f = to_fn_once(|| drop(x)); // OK -- FnOnce
24     }
25     // By-value cases
26     {
27         let x = Box::new(0);
28         let f = to_fn(move || drop(x)); //~ ERROR cannot move
29     }
30     {
31         let x = Box::new(0);
32         let f = to_fn_mut(move || drop(x)); //~ ERROR cannot move
33     }
34     {
35         let x = Box::new(0);
36         let f = to_fn_once(move || drop(x)); // this one is ok
37     }
38 }