diff --git a/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs b/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs new file mode 100644 index 0000000000..4da2c0c61b --- /dev/null +++ b/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs @@ -0,0 +1,36 @@ +// 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) }; + +// use to first make the closure FnOnce() before making it fn() +fn magic0 R>(f: F) -> F { f } +fn magic1 R>(f: F) -> F { f } + +fn main() { + FOO(); + BAR(44, 45); + let bar: unsafe fn(i32, i32) = BAR; + unsafe { bar(46, 47) }; + let boo: &dyn Fn(i32, i32) = &BAR; + boo(48, 49); + + let f: fn() = ||{}; + f(); + 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(); + // FIXME: This does not even compile?!? + //let h = magic0(|| std::process::exit(0)) as fn() -> !; + //h(); + // Once these tests pass, they should be in separate files as they terminate the process. +} diff --git a/tests/run-pass/mir_coercions.rs b/tests/run-pass/coercions.rs similarity index 100% rename from tests/run-pass/mir_coercions.rs rename to tests/run-pass/coercions.rs diff --git a/tests/run-pass/mir_fat_ptr.rs b/tests/run-pass/fat_ptr.rs similarity index 100% rename from tests/run-pass/mir_fat_ptr.rs rename to tests/run-pass/fat_ptr.rs diff --git a/tests/run-pass/non_capture_closure_to_fn_ptr.rs b/tests/run-pass/non_capture_closure_to_fn_ptr.rs deleted file mode 100644 index e6a5017847..0000000000 --- a/tests/run-pass/non_capture_closure_to_fn_ptr.rs +++ /dev/null @@ -1,20 +0,0 @@ -// 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) }; - -// use to first make the closure FnOnce() before making it fn() -fn magic(f: F) -> F { f } - -fn main() { - FOO(); - BAR(44, 45); - let bar: unsafe fn(i32, i32) = BAR; - unsafe { bar(46, 47) }; - let boo: &dyn Fn(i32, i32) = &BAR; - boo(48, 49); - - let f = magic(||{}) as fn(); - f(); -}