about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-07-13 21:15:21 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-07-13 22:24:11 -0700
commitc8d9cd99fa2f389a69c0c42de9945f46977b11d7 (patch)
treea70feac92e2938627d6300829c670c9b38b8c22c /src/test
parent69656fa4cbafc378fd63f9186d93b0df3cdd9320 (diff)
downloadrust-c8d9cd99fa2f389a69c0c42de9945f46977b11d7.tar.gz
rust-c8d9cd99fa2f389a69c0c42de9945f46977b11d7.zip
Detect `fn` with a body in an `extern` block
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/extern/extern-ffi-fn-with-body.rs11
-rw-r--r--src/test/ui/extern/extern-ffi-fn-with-body.stderr18
2 files changed, 29 insertions, 0 deletions
diff --git a/src/test/ui/extern/extern-ffi-fn-with-body.rs b/src/test/ui/extern/extern-ffi-fn-with-body.rs
new file mode 100644
index 00000000000..4cf563514ea
--- /dev/null
+++ b/src/test/ui/extern/extern-ffi-fn-with-body.rs
@@ -0,0 +1,11 @@
+extern "C" {
+    fn foo() -> i32 { //~ ERROR incorrect `fn` inside `extern` block
+        return 0;
+    }
+}
+
+extern "C" fn bar() -> i32 {
+    return 0;
+}
+
+fn main() {}
diff --git a/src/test/ui/extern/extern-ffi-fn-with-body.stderr b/src/test/ui/extern/extern-ffi-fn-with-body.stderr
new file mode 100644
index 00000000000..02d1ee5a753
--- /dev/null
+++ b/src/test/ui/extern/extern-ffi-fn-with-body.stderr
@@ -0,0 +1,18 @@
+error: incorrect `fn` inside `extern` block
+  --> $DIR/extern-ffi-fn-with-body.rs:2:8
+   |
+LL |   extern "C" {
+   |   ------ `extern` blocks define existing foreign functions and `fn`s inside of them can't have a body
+LL |       fn foo() -> i32 {
+   |  ________^^^__________-
+   | |        |
+   | |        can't have a body
+LL | |         return 0;
+LL | |     }
+   | |_____- this body is invalid here
+   |
+   = help: you might have meant to write a function accessible through ffi, which can be done by writing `extern fn` outside of the `extern` block
+   = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
+
+error: aborting due to previous error
+