]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
1a4d82fc JJ |
2 | // Checks that the Fn trait hierarchy rules permit |
3 | // FnMut or FnOnce to be used where FnMut is implemented. | |
4 | ||
92a42be0 | 5 | #![feature(unboxed_closures, fn_traits)] |
1a4d82fc JJ |
6 | |
7 | struct S; | |
8 | ||
85aaf69f | 9 | impl FnMut<(i32,)> for S { |
85aaf69f | 10 | extern "rust-call" fn call_mut(&mut self, (x,): (i32,)) -> i32 { |
1a4d82fc JJ |
11 | x * x |
12 | } | |
13 | } | |
14 | ||
c34b1796 AL |
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 | ||
85aaf69f | 21 | fn call_it_mut<F:FnMut(i32)->i32>(f: &mut F, x: i32) -> i32 { |
1a4d82fc JJ |
22 | f(x) |
23 | } | |
24 | ||
85aaf69f | 25 | fn call_it_once<F:FnOnce(i32)->i32>(f: F, x: i32) -> i32 { |
1a4d82fc JJ |
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 | } |