2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2014-12-01 08:23:40 -06:00
|
|
|
// Checks that higher-ranked extern fn pointers implement the full range of Fn traits.
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn square(x: &isize) -> isize { (*x) * (*x) }
|
2014-12-01 08:23:40 -06:00
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn call_it<F:Fn(&isize)->isize>(f: &F, x: isize) -> isize {
|
2014-12-01 08:23:40 -06:00
|
|
|
(*f)(&x)
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn call_it_boxed(f: &dyn Fn(&isize) -> isize, x: isize) -> isize {
|
2015-12-02 19:31:49 -06:00
|
|
|
f(&x)
|
2014-12-01 08:23:40 -06:00
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn call_it_mut<F:FnMut(&isize)->isize>(f: &mut F, x: isize) -> isize {
|
2014-12-01 08:23:40 -06:00
|
|
|
(*f)(&x)
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn call_it_once<F:FnOnce(&isize)->isize>(f: F, x: isize) -> isize {
|
2014-12-01 08:23:40 -06:00
|
|
|
f(&x)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = call_it(&square, 22);
|
|
|
|
let x1 = call_it_boxed(&square, 22);
|
|
|
|
let y = call_it_mut(&mut square, 22);
|
|
|
|
let z = call_it_once(square, 22);
|
|
|
|
assert_eq!(x, square(&22));
|
|
|
|
assert_eq!(x1, square(&22));
|
|
|
|
assert_eq!(y, square(&22));
|
|
|
|
assert_eq!(z, square(&22));
|
|
|
|
}
|