2016-03-18 11:48:31 -05:00
|
|
|
fn simple() -> i32 {
|
|
|
|
let y = 10;
|
|
|
|
let f = |x| x + y;
|
|
|
|
f(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn crazy_closure() -> (i32, i32, i32) {
|
|
|
|
fn inner<T: Copy>(t: T) -> (i32, T, T) {
|
|
|
|
struct NonCopy;
|
|
|
|
let x = NonCopy;
|
|
|
|
|
|
|
|
let a = 2;
|
|
|
|
let b = 40;
|
|
|
|
let f = move |y, z, asdf| {
|
|
|
|
drop(x);
|
|
|
|
(a + b + y + z, asdf, t)
|
|
|
|
};
|
|
|
|
f(a, b, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
inner(10)
|
|
|
|
}
|
|
|
|
|
2016-06-17 23:52:24 -05:00
|
|
|
// TODO(solson): Implement closure argument adjustment and uncomment this test.
|
2016-03-18 11:48:31 -05:00
|
|
|
// fn closure_arg_adjustment_problem() -> i64 {
|
|
|
|
// fn once<F: FnOnce(i64)>(f: F) { f(2); }
|
|
|
|
// let mut y = 1;
|
|
|
|
// {
|
|
|
|
// let f = |x| y += x;
|
|
|
|
// once(f);
|
|
|
|
// }
|
|
|
|
// y
|
|
|
|
// }
|
2016-04-22 03:34:14 -05:00
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(simple(), 12);
|
2016-06-17 23:52:24 -05:00
|
|
|
assert_eq!(crazy_closure(), (84, 10, 10));
|
2016-04-22 07:38:46 -05:00
|
|
|
}
|