about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-03-31 19:19:51 +0200
committerGitHub <noreply@github.com>2019-03-31 19:19:51 +0200
commit1909a0303a92c0938e9f57b1c32148cfa2a4ff71 (patch)
tree89f7156bbaecefbf602b4f7d9346de2e40e617b9 /src/test
parent0171fe55986abd7e9ac33839db1676fd3ed6c03a (diff)
parent07021e07edf30384203b43024f5bc81ac84a9574 (diff)
downloadrust-1909a0303a92c0938e9f57b1c32148cfa2a4ff71.tar.gz
rust-1909a0303a92c0938e9f57b1c32148cfa2a4ff71.zip
Rollup merge of #59580 - taiki-e:coerce-closure, r=oli-obk
Allow closure to unsafe fn coercion

Closes #57883
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/coerce-unsafe-closure-to-unsafe-fn-ptr.rs5
-rw-r--r--src/test/run-pass/typeck-closure-to-unsafe-fn-ptr.rs7
2 files changed, 12 insertions, 0 deletions
diff --git a/src/test/compile-fail/coerce-unsafe-closure-to-unsafe-fn-ptr.rs b/src/test/compile-fail/coerce-unsafe-closure-to-unsafe-fn-ptr.rs
new file mode 100644
index 00000000000..36777693fab
--- /dev/null
+++ b/src/test/compile-fail/coerce-unsafe-closure-to-unsafe-fn-ptr.rs
@@ -0,0 +1,5 @@
+fn main() {
+    let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
+    //~^ ERROR E0133
+    let _: unsafe fn() = || unsafe { ::std::pin::Pin::new_unchecked(&0_u8); }; // OK
+}
diff --git a/src/test/run-pass/typeck-closure-to-unsafe-fn-ptr.rs b/src/test/run-pass/typeck-closure-to-unsafe-fn-ptr.rs
new file mode 100644
index 00000000000..fe15b912d60
--- /dev/null
+++ b/src/test/run-pass/typeck-closure-to-unsafe-fn-ptr.rs
@@ -0,0 +1,7 @@
+unsafe fn call_unsafe(func: unsafe fn() -> ()) -> () {
+    func()
+}
+
+pub fn main() {
+    unsafe { call_unsafe(|| {}); }
+}