]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-infer-kind.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-infer-kind.rs
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
7 fn call_fn<F: Fn()>(f: F) {
8     f()
9 }
10
11 fn call_fn_mut<F: FnMut()>(mut f: F) {
12     f()
13 }
14
15 fn call_fn_once<F: FnOnce()>(f: F) {
16     f()
17 }
18
19 fn 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 }