2 #![feature(unboxed_closures, fn_traits)]
4 // Test that unboxing shim for calling rust-call ABI methods through a
5 // trait box works and does not cause an ICE.
7 struct Foo { foo: u32 }
9 impl FnMut<()> for Foo {
10 extern "rust-call" fn call_mut(&mut self, _: ()) -> u32 { self.foo }
13 impl FnOnce<()> for Foo {
15 extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
18 impl FnMut<(u32,)> for Foo {
19 extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
22 impl FnOnce<(u32,)> for Foo {
24 extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
27 impl FnMut<(u32,u32)> for Foo {
28 extern "rust-call" fn call_mut(&mut self, (x, y): (u32, u32)) -> u32 { self.foo + x + y }
31 impl FnOnce<(u32,u32)> for Foo {
33 extern "rust-call" fn call_once(mut self, args: (u32,u32)) -> u32 { self.call_mut(args) }
37 let mut f = Box::new(Foo { foo: 42 }) as Box<dyn FnMut() -> u32>;
38 assert_eq!(f.call_mut(()), 42);
40 let mut f = Box::new(Foo { foo: 40 }) as Box<dyn FnMut(u32) -> u32>;
41 assert_eq!(f.call_mut((2,)), 42);
43 let mut f = Box::new(Foo { foo: 40 }) as Box<dyn FnMut(u32, u32) -> u32>;
44 assert_eq!(f.call_mut((1, 1)), 42);