2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-10-28 06:24:25 -05:00
|
|
|
// Checks that the Fn trait hierarchy rules permit
|
|
|
|
// FnMut or FnOnce to be used where FnMut is implemented.
|
|
|
|
|
2015-12-02 19:31:49 -06:00
|
|
|
#![feature(unboxed_closures, fn_traits)]
|
2014-06-01 20:41:46 -05:00
|
|
|
|
|
|
|
struct S;
|
|
|
|
|
2015-01-12 09:27:25 -06:00
|
|
|
impl FnMut<(i32,)> for S {
|
|
|
|
extern "rust-call" fn call_mut(&mut self, (x,): (i32,)) -> i32 {
|
2014-06-01 20:41:46 -05:00
|
|
|
x * x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 09:08:33 -05:00
|
|
|
impl FnOnce<(i32,)> for S {
|
|
|
|
type Output = i32;
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(mut self, args: (i32,)) -> i32 { self.call_mut(args) }
|
|
|
|
}
|
|
|
|
|
2015-01-12 09:27:25 -06:00
|
|
|
fn call_it_mut<F:FnMut(i32)->i32>(f: &mut F, x: i32) -> i32 {
|
2015-01-05 13:07:10 -06:00
|
|
|
f(x)
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
|
|
|
|
2015-01-12 09:27:25 -06:00
|
|
|
fn call_it_once<F:FnOnce(i32)->i32>(f: F, x: i32) -> i32 {
|
2015-01-05 13:07:10 -06:00
|
|
|
f(x)
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2014-10-28 06:24:25 -05:00
|
|
|
let y = call_it_mut(&mut S, 22);
|
|
|
|
let z = call_it_once(S, 22);
|
|
|
|
assert_eq!(y, z);
|
2014-06-01 20:41:46 -05:00
|
|
|
}
|