2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-10-03 02:57:21 -05:00
|
|
|
// Test by-ref capture of environment in unboxed closure types
|
|
|
|
|
|
|
|
fn call_fn<F: Fn()>(f: F) {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call_fn_mut<F: FnMut()>(mut f: F) {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call_fn_once<F: FnOnce()>(f: F) {
|
|
|
|
f()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-02-18 04:42:01 -06:00
|
|
|
let mut x = 0_usize;
|
|
|
|
let y = 2_usize;
|
2014-10-03 02:57:21 -05:00
|
|
|
|
2015-02-01 11:44:15 -06:00
|
|
|
call_fn(|| assert_eq!(x, 0));
|
|
|
|
call_fn_mut(|| x += y);
|
|
|
|
call_fn_once(|| x += y);
|
2014-10-04 17:34:38 -05:00
|
|
|
assert_eq!(x, y * 2);
|
2014-10-03 02:57:21 -05:00
|
|
|
}
|