Skip to content

Commit cdb0cda

Browse files
committed
---
yaml --- r: 138285 b: refs/heads/master c: f4cb9f4 h: refs/heads/master i: 138283: 056b32f v: v3
1 parent 26660d7 commit cdb0cda

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4a4a4347cbb6cd981cb469f142a8882c5c27e517
2+
refs/heads/master: f4cb9f466383d2c7b9e9c23c9a41e5310fede4a6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)