]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-16739.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / src / test / ui / issues / issue-16739.rs
CommitLineData
b7449926 1// run-pass
1a4d82fc 2#![feature(box_syntax)]
92a42be0 3#![feature(unboxed_closures, fn_traits)]
1a4d82fc
JJ
4
5// Test that unboxing shim for calling rust-call ABI methods through a
6// trait box works and does not cause an ICE.
7
85aaf69f 8struct Foo { foo: u32 }
1a4d82fc 9
85aaf69f 10impl FnMut<()> for Foo {
85aaf69f 11 extern "rust-call" fn call_mut(&mut self, _: ()) -> u32 { self.foo }
1a4d82fc
JJ
12}
13
c34b1796 14impl FnOnce<()> for Foo {
85aaf69f 15 type Output = u32;
c34b1796
AL
16 extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
17}
18
c34b1796 19impl FnMut<(u32,)> for Foo {
85aaf69f 20 extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
1a4d82fc
JJ
21}
22
c34b1796 23impl FnOnce<(u32,)> for Foo {
85aaf69f 24 type Output = u32;
c34b1796
AL
25 extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
26}
27
c34b1796 28impl FnMut<(u32,u32)> for Foo {
85aaf69f 29 extern "rust-call" fn call_mut(&mut self, (x, y): (u32, u32)) -> u32 { self.foo + x + y }
1a4d82fc
JJ
30}
31
c34b1796
AL
32impl FnOnce<(u32,u32)> for Foo {
33 type Output = u32;
34 extern "rust-call" fn call_once(mut self, args: (u32,u32)) -> u32 { self.call_mut(args) }
35}
36
1a4d82fc 37fn main() {
dc9dc135 38 let mut f = box Foo { foo: 42 } as Box<dyn FnMut() -> u32>;
1a4d82fc
JJ
39 assert_eq!(f.call_mut(()), 42);
40
dc9dc135 41 let mut f = box Foo { foo: 40 } as Box<dyn FnMut(u32) -> u32>;
1a4d82fc
JJ
42 assert_eq!(f.call_mut((2,)), 42);
43
dc9dc135 44 let mut f = box Foo { foo: 40 } as Box<dyn FnMut(u32, u32) -> u32>;
1a4d82fc
JJ
45 assert_eq!(f.call_mut((1, 1)), 42);
46}