]> git.proxmox.com Git - rustc.git/blob - tests/ui/issues/issue-18952.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / issues / issue-18952.rs
1 // This issue tests fn_traits overloading on arity.
2 // run-pass
3
4 #![feature(fn_traits)]
5 #![feature(unboxed_closures)]
6
7 struct Foo;
8
9 impl Fn<(isize, isize)> for Foo {
10 extern "rust-call" fn call(&self, args: (isize, isize)) -> Self::Output {
11 println!("{:?}", args);
12 (args.0 + 1, args.1 + 1)
13 }
14 }
15
16 impl FnMut<(isize, isize)> for Foo {
17 extern "rust-call" fn call_mut(&mut self, args: (isize, isize)) -> Self::Output {
18 println!("{:?}", args);
19 (args.0 + 1, args.1 + 1)
20 }
21 }
22
23 impl FnOnce<(isize, isize)> for Foo {
24 type Output = (isize, isize);
25 extern "rust-call" fn call_once(self, args: (isize, isize)) -> Self::Output {
26 println!("{:?}", args);
27 (args.0 + 1, args.1 + 1)
28 }
29 }
30
31 impl Fn<(isize, isize, isize)> for Foo {
32 extern "rust-call" fn call(&self, args: (isize, isize, isize)) -> Self::Output {
33 println!("{:?}", args);
34 (args.0 + 3, args.1 + 3, args.2 + 3)
35 }
36 }
37
38 impl FnMut<(isize, isize, isize)> for Foo {
39 extern "rust-call" fn call_mut(&mut self, args: (isize, isize, isize)) -> Self::Output {
40 println!("{:?}", args);
41 (args.0 + 3, args.1 + 3, args.2 + 3)
42 }
43 }
44 impl FnOnce<(isize, isize, isize)> for Foo {
45 type Output = (isize, isize, isize);
46 extern "rust-call" fn call_once(self, args: (isize, isize, isize)) -> Self::Output {
47 println!("{:?}", args);
48 (args.0 + 3, args.1 + 3, args.2 + 3)
49 }
50 }
51
52 fn main() {
53 let foo = Foo;
54 assert_eq!(foo(1, 1), (2, 2));
55 assert_eq!(foo(1, 1, 1), (4, 4, 4));
56 }