1 // run-pass 2 // Test that we can infer the "kind" of an unboxed closure based on 3 // the expected type. 4 5 // Test by-ref capture of environment in unboxed closure types 6 call_fn<F: Fn()>(f: F)7fn call_fn<F: Fn()>(f: F) { 8 f() 9 } 10 call_fn_mut<F: FnMut()>(mut f: F)11fn call_fn_mut<F: FnMut()>(mut f: F) { 12 f() 13 } 14 call_fn_once<F: FnOnce()>(f: F)15fn call_fn_once<F: FnOnce()>(f: F) { 16 f() 17 } 18 main()19fn main() { 20 let mut x = 0_usize; 21 let y = 2_usize; 22 23 call_fn(|| assert_eq!(x, 0)); 24 call_fn_mut(|| x += y); 25 call_fn_once(|| x += y); 26 assert_eq!(x, y * 2); 27 } 28