2014-10-16 23:56:53 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-01-07 19:25:56 -06:00
|
|
|
#![allow(unknown_features)]
|
|
|
|
#![feature(box_syntax)]
|
2014-10-16 23:56:53 -05:00
|
|
|
#![feature(unboxed_closures)]
|
|
|
|
|
|
|
|
// Test that unboxing shim for calling rust-call ABI methods through a
|
2014-11-20 11:12:38 -06:00
|
|
|
// trait box works and does not cause an ICE.
|
2014-10-16 23:56:53 -05:00
|
|
|
|
|
|
|
struct Foo { foo: uint }
|
|
|
|
|
2014-11-20 11:12:38 -06:00
|
|
|
impl FnMut<(), uint> for Foo {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, _: ()) -> uint { self.foo }
|
2014-10-16 23:56:53 -05:00
|
|
|
}
|
|
|
|
|
2014-11-20 11:12:38 -06:00
|
|
|
impl FnMut<(uint,), uint> for Foo {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, (x,): (uint,)) -> uint { self.foo + x }
|
2014-10-16 23:56:53 -05:00
|
|
|
}
|
|
|
|
|
2014-11-20 11:12:38 -06:00
|
|
|
impl FnMut<(uint, uint), uint> for Foo {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, (x, y): (uint, uint)) -> uint { self.foo + x + y }
|
2014-10-16 23:56:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-11-20 11:12:38 -06:00
|
|
|
let mut f = box Foo { foo: 42 } as Box<FnMut<(), uint>>;
|
|
|
|
assert_eq!(f.call_mut(()), 42);
|
2014-10-16 23:56:53 -05:00
|
|
|
|
2014-11-20 11:12:38 -06:00
|
|
|
let mut f = box Foo { foo: 40 } as Box<FnMut<(uint,), uint>>;
|
|
|
|
assert_eq!(f.call_mut((2,)), 42);
|
2014-10-16 23:56:53 -05:00
|
|
|
|
2014-11-20 11:12:38 -06:00
|
|
|
let mut f = box Foo { foo: 40 } as Box<FnMut<(uint, uint), uint>>;
|
|
|
|
assert_eq!(f.call_mut((1, 1)), 42);
|
2014-10-16 23:56:53 -05:00
|
|
|
}
|