Skip to content

Commit 3c0d343

Browse files
committed
Auto merge of #1079 - RalfJung:coercion-error, r=RalfJung
Test diverging closure coercion Adds a test for #1075. Depends on rust-lang/rust#66827.
2 parents ae38f48 + 42732cc commit 3c0d343

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f5c81e0a986e4285d3d0fd781a1bd475753eb12c
1+
4af3ee8ee2a2bc1286b021db7600ba990359cf3f

tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ static FOO: fn() = || { assert_ne!(42, 43) };
55
static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) };
66

77
// 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 }
8+
fn force_once0<R, F: FnOnce() -> R>(f: F) -> F { f }
9+
fn force_once1<T, R, F: FnOnce(T) -> R>(f: F) -> F { f }
10+
fn force_mut0<R, F: FnMut() -> R>(f: F) -> F { f }
11+
fn force_mut1<T, R, F: FnMut(T) -> R>(f: F) -> F { f }
1012

1113
fn main() {
1214
FOO();
@@ -18,19 +20,15 @@ fn main() {
1820

1921
let f: fn() = ||{};
2022
f();
21-
let f = magic0(||{}) as fn();
23+
let f = force_once0(||{}) as fn();
24+
f();
25+
let f = force_mut0(||{}) as fn();
2226
f();
2327

2428
let g: fn(i32) = |i| assert_eq!(i, 2);
2529
g(2);
26-
let g = magic1(|i| assert_eq!(i, 2)) as fn(i32);
30+
let g = force_once1(|i| assert_eq!(i, 2)) as fn(i32);
31+
g(2);
32+
let g = force_mut1(|i| assert_eq!(i, 2)) as fn(i32);
2733
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.
3634
}

tests/run-pass/issue-miri-1075.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let f: fn() -> ! = || std::process::exit(0);
3+
f();
4+
5+
// FIXME: Also add a test for <https://github.com/rust-lang/rust/issues/66738>, once that is fixed.
6+
}

0 commit comments

Comments
 (0)