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.
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.
11 #![feature(unboxed_closures)]
13 // Test that unboxing shim for calling rust-call ABI methods through a
14 // trait box works and does not cause an ICE.
16 struct Foo { foo: uint }
18 impl FnMut<(), uint> for Foo {
19 extern "rust-call" fn call_mut(&mut self, _: ()) -> uint { self.foo }
22 impl FnMut<(uint,), uint> for Foo {
23 extern "rust-call" fn call_mut(&mut self, (x,): (uint,)) -> uint { self.foo + x }
26 impl FnMut<(uint, uint), uint> for Foo {
27 extern "rust-call" fn call_mut(&mut self, (x, y): (uint, uint)) -> uint { self.foo + x + y }
31 let mut f = box Foo { foo: 42 } as Box<FnMut<(), uint>>;
32 assert_eq!(f.call_mut(()), 42);
34 let mut f = box Foo { foo: 40 } as Box<FnMut<(uint,), uint>>;
35 assert_eq!(f.call_mut((2,)), 42);
37 let mut f = box Foo { foo: 40 } as Box<FnMut<(uint, uint), uint>>;
38 assert_eq!(f.call_mut((1, 1)), 42);