Auto merge of #1079 - RalfJung:coercion-error, r=RalfJung
Test diverging closure coercion Adds a test for https://github.com/rust-lang/miri/issues/1075. Depends on https://github.com/rust-lang/rust/pull/66827.
This commit is contained in:
commit
3c0d3439ee
@ -1 +1 @@
|
||||
f5c81e0a986e4285d3d0fd781a1bd475753eb12c
|
||||
4af3ee8ee2a2bc1286b021db7600ba990359cf3f
|
||||
|
@ -5,8 +5,10 @@ static FOO: fn() = || { assert_ne!(42, 43) };
|
||||
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: FnOnce() -> R>(f: F) -> F { f }
|
||||
fn magic1<T, R, F: FnOnce(T) -> R>(f: F) -> F { f }
|
||||
fn force_once0<R, F: FnOnce() -> R>(f: F) -> F { f }
|
||||
fn force_once1<T, R, F: FnOnce(T) -> R>(f: F) -> F { f }
|
||||
fn force_mut0<R, F: FnMut() -> R>(f: F) -> F { f }
|
||||
fn force_mut1<T, R, F: FnMut(T) -> R>(f: F) -> F { f }
|
||||
|
||||
fn main() {
|
||||
FOO();
|
||||
@ -18,19 +20,15 @@ fn main() {
|
||||
|
||||
let f: fn() = ||{};
|
||||
f();
|
||||
let f = magic0(||{}) as fn();
|
||||
let f = force_once0(||{}) as fn();
|
||||
f();
|
||||
let f = force_mut0(||{}) 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);
|
||||
let g = force_once1(|i| assert_eq!(i, 2)) as fn(i32);
|
||||
g(2);
|
||||
let g = force_mut1(|i| assert_eq!(i, 2)) as fn(i32);
|
||||
g(2);
|
||||
|
||||
// FIXME: This fails with "invalid use of NULL pointer" <https://github.com/rust-lang/miri/issues/1075>
|
||||
//let h: fn() -> ! = || std::process::exit(0);
|
||||
//h();
|
||||
// FIXME: This does not even compile?!? <https://github.com/rust-lang/rust/issues/66738>
|
||||
//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.
|
||||
}
|
||||
|
6
tests/run-pass/issue-miri-1075.rs
Normal file
6
tests/run-pass/issue-miri-1075.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let f: fn() -> ! = || std::process::exit(0);
|
||||
f();
|
||||
|
||||
// FIXME: Also add a test for <https://github.com/rust-lang/rust/issues/66738>, once that is fixed.
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user