Skip to content

Commit 24d0b39

Browse files
committed
Auto merge of #1076 - RalfJung:coercion-test, r=RalfJung
test closure-to-fn-ptr coercions a bit more Also add some commented-out failing tests, Cc rust-lang/rust#66738 #1075
2 parents 29b53f9 + 2152258 commit 24d0b39

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// allow(const_err) to work around a bug in warnings
2+
#[allow(const_err)]
3+
static FOO: fn() = || { assert_ne!(42, 43) };
4+
#[allow(const_err)]
5+
static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) };
6+
7+
// use to first make the closure FnOnce() before making it fn()
8+
fn magic0<R, F: FnOnce() -> R>(f: F) -> F { f }
9+
fn magic1<T, R, F: FnOnce(T) -> R>(f: F) -> F { f }
10+
11+
fn main() {
12+
FOO();
13+
BAR(44, 45);
14+
let bar: unsafe fn(i32, i32) = BAR;
15+
unsafe { bar(46, 47) };
16+
let boo: &dyn Fn(i32, i32) = &BAR;
17+
boo(48, 49);
18+
19+
let f: fn() = ||{};
20+
f();
21+
let f = magic0(||{}) as fn();
22+
f();
23+
24+
let g: fn(i32) = |i| assert_eq!(i, 2);
25+
g(2);
26+
let g = magic1(|i| assert_eq!(i, 2)) as fn(i32);
27+
g(2);
28+
29+
// FIXME: This fails with "invalid use of NULL pointer" <https://github.com/rust-lang/miri/issues/1075>
30+
//let h: fn() -> ! = || std::process::exit(0);
31+
//h();
32+
// FIXME: This does not even compile?!? <https://github.com/rust-lang/rust/issues/66738>
33+
//let h = magic0(|| std::process::exit(0)) as fn() -> !;
34+
//h();
35+
// Once these tests pass, they should be in separate files as they terminate the process.
36+
}
File renamed without changes.
File renamed without changes.

tests/run-pass/non_capture_closure_to_fn_ptr.rs

-20
This file was deleted.

0 commit comments

Comments
 (0)