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 to_fn<A,F:Fn<A>>(f: F) -> F7fn to_fn<A,F:Fn<A>>(f: F) -> F { f } to_fn_mut<A,F:FnMut<A>>(f: F) -> F8fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f } to_fn_once<A,F:FnOnce<A>>(f: F) -> F9fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f } 10 main()11fn 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 } 39