]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unboxed-closures/unboxed-closures-by-ref.rs
Rollup merge of #95376 - WaffleLapkin:drain_keep_rest, r=dtolnay
[rust.git] / src / test / ui / unboxed-closures / unboxed-closures-by-ref.rs
1 // run-pass
2 // Test by-ref capture of environment in unboxed closure types
3
4 fn call_fn<F: Fn()>(f: F) {
5     f()
6 }
7
8 fn call_fn_mut<F: FnMut()>(mut f: F) {
9     f()
10 }
11
12 fn call_fn_once<F: FnOnce()>(f: F) {
13     f()
14 }
15
16 fn main() {
17     let mut x = 0_usize;
18     let y = 2_usize;
19
20     call_fn(|| assert_eq!(x, 0));
21     call_fn_mut(|| x += y);
22     call_fn_once(|| x += y);
23     assert_eq!(x, y * 2);
24 }