]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-16739.rs
point at private fields in struct literal
[rust.git] / src / test / ui / issues / issue-16739.rs
1 // run-pass
2 #![feature(box_syntax)]
3 #![feature(unboxed_closures, fn_traits)]
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
8 struct Foo { foo: u32 }
9
10 impl FnMut<()> for Foo {
11     extern "rust-call" fn call_mut(&mut self, _: ()) -> u32 { self.foo }
12 }
13
14 impl FnOnce<()> for Foo {
15     type Output = u32;
16     extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
17 }
18
19 impl FnMut<(u32,)> for Foo {
20     extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
21 }
22
23 impl FnOnce<(u32,)> for Foo {
24     type Output = u32;
25     extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
26 }
27
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 }
30 }
31
32 impl 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
37 fn main() {
38     let mut f = box Foo { foo: 42 } as Box<dyn FnMut() -> u32>;
39     assert_eq!(f.call_mut(()), 42);
40
41     let mut f = box Foo { foo: 40 } as Box<dyn FnMut(u32) -> u32>;
42     assert_eq!(f.call_mut((2,)), 42);
43
44     let mut f = box Foo { foo: 40 } as Box<dyn FnMut(u32, u32) -> u32>;
45     assert_eq!(f.call_mut((1, 1)), 42);
46 }