2018-11-04 10:27:09 +00:00
|
|
|
// This issue tests fn_traits overloading on arity.
|
2018-11-08 09:39:46 +00:00
|
|
|
// run-pass
|
2018-11-04 10:27:09 +00:00
|
|
|
|
|
|
|
#![feature(fn_traits)]
|
|
|
|
#![feature(unboxed_closures)]
|
|
|
|
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Fn<(isize, isize)> for Foo {
|
|
|
|
extern "rust-call" fn call(&self, args: (isize, isize)) -> Self::Output {
|
|
|
|
println!("{:?}", args);
|
2018-11-27 14:15:27 +00:00
|
|
|
(args.0 + 1, args.1 + 1)
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FnMut<(isize, isize)> for Foo {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, args: (isize, isize)) -> Self::Output {
|
|
|
|
println!("{:?}", args);
|
2018-11-27 14:15:27 +00:00
|
|
|
(args.0 + 1, args.1 + 1)
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FnOnce<(isize, isize)> for Foo {
|
2018-11-27 14:15:27 +00:00
|
|
|
type Output = (isize, isize);
|
2018-11-04 10:27:09 +00:00
|
|
|
extern "rust-call" fn call_once(self, args: (isize, isize)) -> Self::Output {
|
|
|
|
println!("{:?}", args);
|
2018-11-27 14:15:27 +00:00
|
|
|
(args.0 + 1, args.1 + 1)
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Fn<(isize, isize, isize)> for Foo {
|
|
|
|
extern "rust-call" fn call(&self, args: (isize, isize, isize)) -> Self::Output {
|
|
|
|
println!("{:?}", args);
|
2018-11-27 14:15:27 +00:00
|
|
|
(args.0 + 3, args.1 + 3, args.2 + 3)
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FnMut<(isize, isize, isize)> for Foo {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, args: (isize, isize, isize)) -> Self::Output {
|
|
|
|
println!("{:?}", args);
|
2018-11-27 14:15:27 +00:00
|
|
|
(args.0 + 3, args.1 + 3, args.2 + 3)
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
impl FnOnce<(isize, isize, isize)> for Foo {
|
2018-11-27 14:15:27 +00:00
|
|
|
type Output = (isize, isize, isize);
|
2018-11-04 10:27:09 +00:00
|
|
|
extern "rust-call" fn call_once(self, args: (isize, isize, isize)) -> Self::Output {
|
|
|
|
println!("{:?}", args);
|
2018-11-27 14:15:27 +00:00
|
|
|
(args.0 + 3, args.1 + 3, args.2 + 3)
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let foo = Foo;
|
2018-11-27 14:15:27 +00:00
|
|
|
assert_eq!(foo(1, 1), (2, 2));
|
|
|
|
assert_eq!(foo(1, 1, 1), (4, 4, 4));
|
2018-11-04 10:27:09 +00:00
|
|
|
}
|