about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2024-04-25 16:14:22 -0300
committerSantiago Pastorino <spastorino@gmail.com>2024-06-04 14:19:42 -0300
commit46cd80b691f0e127076b6dcd1bf9285c3e608d4a (patch)
tree6fcdcd165a94b3a3db6a16e4760192e3988a2d8f
parent6d670b74e59de5e2f12e0d19b46b7939e4cd4a31 (diff)
downloadrust-46cd80b691f0e127076b6dcd1bf9285c3e608d4a.tar.gz
rust-46cd80b691f0e127076b6dcd1bf9285c3e608d4a.zip
Test that unsafe extern defines unsafe fns
-rw-r--r--tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr11
-rw-r--r--tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr11
-rw-r--r--tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs21
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr
new file mode 100644
index 00000000000..a94f8d74236
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2021.stderr
@@ -0,0 +1,11 @@
+error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe function or block
+  --> $DIR/extern-items-unsafe.rs:11:5
+   |
+LL |     test1(i);
+   |     ^^^^^^^^ call to unsafe function
+   |
+   = note: consult the function's documentation for information on how to avoid undefined behavior
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr
new file mode 100644
index 00000000000..c187dac1152
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.edition2024.stderr
@@ -0,0 +1,11 @@
+error[E0133]: call to unsafe function `test1` is unsafe and requires unsafe block
+  --> $DIR/extern-items-unsafe.rs:11:5
+   |
+LL |     test1(i);
+   |     ^^^^^^^^ call to unsafe function
+   |
+   = note: consult the function's documentation for information on how to avoid undefined behavior
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs
new file mode 100644
index 00000000000..70f3c0afe7c
--- /dev/null
+++ b/tests/ui/rust-2024/unsafe-extern-blocks/extern-items-unsafe.rs
@@ -0,0 +1,21 @@
+//@ revisions: edition2021 edition2024
+//@[edition2021] edition:2021
+//@[edition2024] edition:2024
+//@[edition2024] compile-flags: -Zunstable-options
+
+unsafe extern "C" {
+    fn test1(i: i32);
+}
+
+fn test2(i: i32) {
+    test1(i);
+    //~^ ERROR: call to unsafe function `test1` is unsafe
+}
+
+fn test3(i: i32) {
+    unsafe {
+        test1(i);
+    }
+}
+
+fn main() {}