2 #![feature(box_syntax)]
3 #![feature(unboxed_closures, fn_traits)]
5 // Test that unboxing shim for calling rust-call ABI methods through a
6 // trait box works and does not cause an ICE.
8 struct Foo { foo: u32 }
10 impl FnMut<()> for Foo {
11 extern "rust-call" fn call_mut(&mut self, _: ()) -> u32 { self.foo }
14 impl FnOnce<()> for Foo {
16 extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
19 impl FnMut<(u32,)> for Foo {
20 extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
23 impl FnOnce<(u32,)> for Foo {
25 extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
28 impl FnMut<(u32,u32)> for Foo {
29 extern "rust-call" fn call_mut(&mut self, (x, y): (u32, u32)) -> u32 { self.foo + x + y }
32 impl FnOnce<(u32,u32)> for Foo {
34 extern "rust-call" fn call_once(mut self, args: (u32,u32)) -> u32 { self.call_mut(args) }
38 let mut f = box Foo { foo: 42 } as Box<dyn FnMut() -> u32>;
39 assert_eq!(f.call_mut(()), 42);
41 let mut f = box Foo { foo: 40 } as Box<dyn FnMut(u32) -> u32>;
42 assert_eq!(f.call_mut((2,)), 42);
44 let mut f = box Foo { foo: 40 } as Box<dyn FnMut(u32, u32) -> u32>;
45 assert_eq!(f.call_mut((1, 1)), 42);