|
| 1 | +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +#![feature(unboxed_closures)] |
| 12 | + |
| 13 | +// Test that unboxing shim for calling rust-call ABI methods through a |
| 14 | +// trait box works and does not cause an ICE |
| 15 | + |
| 16 | +struct Foo { foo: uint } |
| 17 | + |
| 18 | +impl FnOnce<(), uint> for Foo { |
| 19 | + #[rust_call_abi_hack] |
| 20 | + fn call_once(self, _: ()) -> uint { self.foo } |
| 21 | +} |
| 22 | + |
| 23 | +impl FnOnce<(uint,), uint> for Foo { |
| 24 | + #[rust_call_abi_hack] |
| 25 | + fn call_once(self, (x,): (uint,)) -> uint { self.foo + x } |
| 26 | +} |
| 27 | + |
| 28 | +impl FnOnce<(uint, uint), uint> for Foo { |
| 29 | + #[rust_call_abi_hack] |
| 30 | + fn call_once(self, (x, y): (uint, uint)) -> uint { self.foo + x + y } |
| 31 | +} |
| 32 | + |
| 33 | +fn main() { |
| 34 | + let f = box Foo { foo: 42 } as Box<FnOnce<(), uint>>; |
| 35 | + assert_eq!(f.call_once(()), 42); |
| 36 | + |
| 37 | + let f = box Foo { foo: 40 } as Box<FnOnce<(uint,), uint>>; |
| 38 | + assert_eq!(f.call_once((2,)), 42); |
| 39 | + |
| 40 | + let f = box Foo { foo: 40 } as Box<FnOnce<(uint, uint), uint>>; |
| 41 | + assert_eq!(f.call_once((1, 1)), 42); |
| 42 | +} |
0 commit comments