2017-02-28 05:35:00 -06:00
|
|
|
// allow(const_err) to work around a bug in warnings
|
|
|
|
#[allow(const_err)]
|
|
|
|
static FOO: fn() = || { assert_ne!(42, 43) };
|
|
|
|
#[allow(const_err)]
|
|
|
|
static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) };
|
|
|
|
|
2018-08-27 10:08:42 -05:00
|
|
|
// use to first make the closure FnOnce() before making it fn()
|
2019-11-25 08:01:05 -06:00
|
|
|
fn magic0<R, F: FnOnce() -> R>(f: F) -> F { f }
|
|
|
|
fn magic1<T, R, F: FnOnce(T) -> R>(f: F) -> F { f }
|
2018-08-27 10:08:42 -05:00
|
|
|
|
2017-02-28 05:35:00 -06:00
|
|
|
fn main() {
|
|
|
|
FOO();
|
|
|
|
BAR(44, 45);
|
|
|
|
let bar: unsafe fn(i32, i32) = BAR;
|
|
|
|
unsafe { bar(46, 47) };
|
2019-05-30 03:58:30 -05:00
|
|
|
let boo: &dyn Fn(i32, i32) = &BAR;
|
2017-02-28 05:35:00 -06:00
|
|
|
boo(48, 49);
|
2018-08-27 10:08:42 -05:00
|
|
|
|
2019-11-25 08:01:05 -06:00
|
|
|
let f: fn() = ||{};
|
2018-08-27 10:08:42 -05:00
|
|
|
f();
|
2019-11-25 08:01:05 -06:00
|
|
|
let f = magic0(||{}) as fn();
|
|
|
|
f();
|
|
|
|
|
|
|
|
let g: fn(i32) = |i| assert_eq!(i, 2);
|
|
|
|
g(2);
|
|
|
|
let g = magic1(|i| assert_eq!(i, 2)) as fn(i32);
|
|
|
|
g(2);
|
|
|
|
|
|
|
|
// FIXME: This fails with "invalid use of NULL pointer"
|
|
|
|
//let h: fn() -> ! = || std::process::exit(0);
|
|
|
|
//h();
|
2019-11-25 08:08:24 -06:00
|
|
|
// FIXME: This does not even compile?!? <https://github.com/rust-lang/rust/issues/66738>
|
2019-11-25 08:01:05 -06:00
|
|
|
//let h = magic0(|| std::process::exit(0)) as fn() -> !;
|
|
|
|
//h();
|
2019-11-25 08:08:24 -06:00
|
|
|
// Once these tests pass, they should be in separate files as they terminate the process.
|
2017-02-28 05:35:00 -06:00
|
|
|
}
|