2022-07-30 05:37:48 +00:00
|
|
|
#![feature(unboxed_closures, tuple_trait)]
|
2014-10-15 01:35:40 +00:00
|
|
|
|
|
|
|
// Tests that we can't move out of an unboxed closure environment
|
|
|
|
// if the upvar is captured by ref or the closure takes self by
|
|
|
|
// reference.
|
|
|
|
|
2022-07-30 05:37:48 +00:00
|
|
|
fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f }
|
|
|
|
fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f }
|
|
|
|
fn to_fn_once<A:std::marker::Tuple,F:FnOnce<A>>(f: F) -> F { f }
|
2015-02-03 16:32:26 +00:00
|
|
|
|
2014-10-15 01:35:40 +00:00
|
|
|
fn main() {
|
|
|
|
// By-ref cases
|
|
|
|
{
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Box::new(0);
|
2015-02-03 16:32:26 +00:00
|
|
|
let f = to_fn(|| drop(x)); //~ ERROR cannot move
|
2014-10-15 01:35:40 +00:00
|
|
|
}
|
|
|
|
{
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Box::new(0);
|
2015-02-03 16:32:26 +00:00
|
|
|
let f = to_fn_mut(|| drop(x)); //~ ERROR cannot move
|
2014-10-15 01:35:40 +00:00
|
|
|
}
|
|
|
|
{
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Box::new(0);
|
2015-02-03 16:32:26 +00:00
|
|
|
let f = to_fn_once(|| drop(x)); // OK -- FnOnce
|
2014-10-15 01:35:40 +00:00
|
|
|
}
|
|
|
|
// By-value cases
|
|
|
|
{
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Box::new(0);
|
2015-02-03 16:32:26 +00:00
|
|
|
let f = to_fn(move || drop(x)); //~ ERROR cannot move
|
2014-10-15 01:35:40 +00:00
|
|
|
}
|
|
|
|
{
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Box::new(0);
|
2015-02-03 16:32:26 +00:00
|
|
|
let f = to_fn_mut(move || drop(x)); //~ ERROR cannot move
|
2014-10-15 01:35:40 +00:00
|
|
|
}
|
|
|
|
{
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Box::new(0);
|
2015-02-03 16:32:26 +00:00
|
|
|
let f = to_fn_once(move || drop(x)); // this one is ok
|
2014-10-15 01:35:40 +00:00
|
|
|
}
|
|
|
|
}
|