about summary refs log tree commit diff
path: root/tests/ui/unsafe
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2025-08-20 14:02:39 -0400
committerOneirical <manchot@videotron.ca>2025-08-27 00:23:26 -0400
commit2e659f58940a31fa625e88f75f78111ed773f32d (patch)
tree7b7574337cfe2a195a94a3c2dd12035e6eb7c136 /tests/ui/unsafe
parente8a792daf500b5ff8097896ddb6cc037abe92487 (diff)
downloadrust-2e659f58940a31fa625e88f75f78111ed773f32d.tar.gz
rust-2e659f58940a31fa625e88f75f78111ed773f32d.zip
Add test batch 1
Diffstat (limited to 'tests/ui/unsafe')
-rw-r--r--tests/ui/unsafe/auxiliary/aux-5844.rs3
-rw-r--r--tests/ui/unsafe/extern-function-requires-unsafe-5844.rs8
-rw-r--r--tests/ui/unsafe/extern-function-requires-unsafe-5844.stderr11
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/ui/unsafe/auxiliary/aux-5844.rs b/tests/ui/unsafe/auxiliary/aux-5844.rs
new file mode 100644
index 00000000000..ea83378cad6
--- /dev/null
+++ b/tests/ui/unsafe/auxiliary/aux-5844.rs
@@ -0,0 +1,3 @@
+extern "C" {
+    pub fn rand() -> u32;
+}
diff --git a/tests/ui/unsafe/extern-function-requires-unsafe-5844.rs b/tests/ui/unsafe/extern-function-requires-unsafe-5844.rs
new file mode 100644
index 00000000000..11863ce647a
--- /dev/null
+++ b/tests/ui/unsafe/extern-function-requires-unsafe-5844.rs
@@ -0,0 +1,8 @@
+// https://github.com/rust-lang/rust/issues/5844
+//@aux-build:aux-5844.rs
+
+extern crate aux_5844;
+
+fn main() {
+    aux_5844::rand(); //~ ERROR: requires unsafe
+}
diff --git a/tests/ui/unsafe/extern-function-requires-unsafe-5844.stderr b/tests/ui/unsafe/extern-function-requires-unsafe-5844.stderr
new file mode 100644
index 00000000000..44dee178991
--- /dev/null
+++ b/tests/ui/unsafe/extern-function-requires-unsafe-5844.stderr
@@ -0,0 +1,11 @@
+error[E0133]: call to unsafe function `rand` is unsafe and requires unsafe function or block
+  --> $DIR/extern-function-requires-unsafe-5844.rs:7:5
+   |
+LL |     aux_5844::rand();
+   |     ^^^^^^^^^^^^^^^^ 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`.