]> git.lizzy.rs Git - rust.git/blob - tests/ui/unboxed-closures/unboxed-closures-manual-impl.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / unboxed-closures / unboxed-closures-manual-impl.rs
1 // run-pass
2 #![feature(unboxed_closures, fn_traits)]
3
4 struct S;
5
6 impl FnMut<(i32,)> for S {
7     extern "rust-call" fn call_mut(&mut self, (x,): (i32,)) -> i32 {
8         x * x
9     }
10 }
11
12 impl FnOnce<(i32,)> for S {
13     type Output = i32;
14
15     extern "rust-call" fn call_once(mut self, args: (i32,)) -> i32 { self.call_mut(args) }
16 }
17
18 fn call_it<F:FnMut(i32)->i32>(mut f: F, x: i32) -> i32 {
19     f(x) + 3
20 }
21
22 fn call_box(f: &mut dyn FnMut(i32) -> i32, x: i32) -> i32 {
23     f(x) + 3
24 }
25
26 fn main() {
27     let x = call_it(S, 1);
28     let y = call_box(&mut S, 1);
29     assert_eq!(x, 4);
30     assert_eq!(y, 4);
31 }