]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-fnmut-as-fnonce.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-fnmut-as-fnonce.rs
1 // run-pass
2 // Checks that the Fn trait hierarchy rules permit
3 // FnMut or FnOnce to be used where FnMut is implemented.
4
5 #![feature(unboxed_closures, fn_traits)]
6
7 struct S;
8
9 impl FnMut<(i32,)> for S {
10     extern "rust-call" fn call_mut(&mut self, (x,): (i32,)) -> i32 {
11         x * x
12     }
13 }
14
15 impl FnOnce<(i32,)> for S {
16     type Output = i32;
17
18     extern "rust-call" fn call_once(mut self, args: (i32,)) -> i32 { self.call_mut(args) }
19 }
20
21 fn call_it_mut<F:FnMut(i32)->i32>(f: &mut F, x: i32) -> i32 {
22     f(x)
23 }
24
25 fn call_it_once<F:FnOnce(i32)->i32>(f: F, x: i32) -> i32 {
26     f(x)
27 }
28
29 fn main() {
30     let y = call_it_mut(&mut S, 22);
31     let z = call_it_once(S, 22);
32     assert_eq!(y, z);
33 }