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