Skip to content

Commit bba9359

Browse files
committed
expand coerce fn test
1 parent ae38f48 commit bba9359

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs

Lines changed: 10 additions & 4 deletions
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,12 +20,16 @@ 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);
2834

2935
// FIXME: This fails with "invalid use of NULL pointer" <https://github.com/rust-lang/miri/issues/1075>

0 commit comments

Comments
 (0)