]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-16739.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[rust.git] / src / test / run-pass / issue-16739.rs
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     extern "rust-call" fn call_once(self, _: ()) -> uint { self.foo }
20 }
21
22 impl FnOnce<(uint,), uint> for Foo {
23     extern "rust-call" fn call_once(self, (x,): (uint,)) -> uint { self.foo + x }
24 }
25
26 impl FnOnce<(uint, uint), uint> for Foo {
27     extern "rust-call" fn call_once(self, (x, y): (uint, uint)) -> uint { self.foo + x + y }
28 }
29
30 fn main() {
31     let f = box Foo { foo: 42 } as Box<FnOnce<(), uint>>;
32     assert_eq!(f.call_once(()), 42);
33
34     let f = box Foo { foo: 40 } as Box<FnOnce<(uint,), uint>>;
35     assert_eq!(f.call_once((2,)), 42);
36
37     let f = box Foo { foo: 40 } as Box<FnOnce<(uint, uint), uint>>;
38     assert_eq!(f.call_once((1, 1)), 42);
39 }