From 51d47e8dc5a94d60ea0ef321cf81544d2908a216 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Nov 2019 15:01:05 +0100 Subject: [PATCH 1/4] test closure-to-fn-ptr coercions a bit more --- .../run-pass/non_capture_closure_to_fn_ptr.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/run-pass/non_capture_closure_to_fn_ptr.rs b/tests/run-pass/non_capture_closure_to_fn_ptr.rs index e6a5017847..d404daef2c 100644 --- a/tests/run-pass/non_capture_closure_to_fn_ptr.rs +++ b/tests/run-pass/non_capture_closure_to_fn_ptr.rs @@ -5,7 +5,8 @@ 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 magic(f: F) -> F { f } +fn magic0 R>(f: F) -> F { f } +fn magic1 R>(f: F) -> F { f } fn main() { FOO(); @@ -15,6 +16,20 @@ fn main() { let boo: &dyn Fn(i32, i32) = &BAR; boo(48, 49); - let f = magic(||{}) as fn(); + 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(); } From d16e12b0a4b3b525c2aaac7af05a1494f4d3a7bc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Nov 2019 15:08:24 +0100 Subject: [PATCH 2/4] rename test and add some references --- ...re_to_fn_ptr.rs => coerce_non_capture_closure_to_fn_ptr.rs} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename tests/run-pass/{non_capture_closure_to_fn_ptr.rs => coerce_non_capture_closure_to_fn_ptr.rs} (83%) diff --git a/tests/run-pass/non_capture_closure_to_fn_ptr.rs b/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs similarity index 83% rename from tests/run-pass/non_capture_closure_to_fn_ptr.rs rename to tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs index d404daef2c..30e1768837 100644 --- a/tests/run-pass/non_capture_closure_to_fn_ptr.rs +++ b/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs @@ -29,7 +29,8 @@ fn main() { // FIXME: This fails with "invalid use of NULL pointer" //let h: fn() -> ! = || std::process::exit(0); //h(); - // FIXME: This does not even compile?!? + // 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. } From 66dc939787d7b5df2bc4866ab69fe7cc4d980307 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Nov 2019 15:08:47 +0100 Subject: [PATCH 3/4] rename some more tests --- tests/run-pass/{mir_coercions.rs => coercions.rs} | 0 tests/run-pass/{mir_fat_ptr.rs => fat_ptr.rs} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/run-pass/{mir_coercions.rs => coercions.rs} (100%) rename tests/run-pass/{mir_fat_ptr.rs => fat_ptr.rs} (100%) 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 From 2152258b04ba3eb2f7f560ff7b793fb277d29077 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 25 Nov 2019 15:10:39 +0100 Subject: [PATCH 4/4] and another reference --- tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 30e1768837..4da2c0c61b 100644 --- a/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs +++ b/tests/run-pass/coerce_non_capture_closure_to_fn_ptr.rs @@ -26,7 +26,7 @@ fn main() { let g = magic1(|i| assert_eq!(i, 2)) as fn(i32); g(2); - // FIXME: This fails with "invalid use of NULL pointer" + // FIXME: This fails with "invalid use of NULL pointer" //let h: fn() -> ! = || std::process::exit(0); //h(); // FIXME: This does not even compile?!?