summaryrefslogtreecommitdiffstats
path: root/src/test/ui/unsafe
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /src/test/ui/unsafe
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/unsafe')
-rw-r--r--src/test/ui/unsafe/unsafe-not-inherited.rs26
-rw-r--r--src/test/ui/unsafe/unsafe-not-inherited.stderr24
2 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ui/unsafe/unsafe-not-inherited.rs b/src/test/ui/unsafe/unsafe-not-inherited.rs
new file mode 100644
index 000000000..6d797caa0
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-not-inherited.rs
@@ -0,0 +1,26 @@
+#![allow(unused, dead_code)]
+
+static mut FOO: u64 = 0;
+
+fn static_mod() {
+ unsafe {static BAR: u64 = FOO;}
+ //~^ ERROR: use of mutable static is unsafe
+ //~| NOTE: use of mutable static
+ //~| NOTE: mutable statics can be mutated by multiple threads
+ //~| NOTE: items do not inherit unsafety
+}
+
+unsafe fn unsafe_call() {}
+fn foo() {
+ unsafe {
+ //~^ NOTE: items do not inherit unsafety
+ fn bar() {
+ unsafe_call();
+ //~^ ERROR: call to unsafe function
+ //~| NOTE: call to unsafe function
+ //~| NOTE: consult the function's documentation
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/unsafe/unsafe-not-inherited.stderr b/src/test/ui/unsafe/unsafe-not-inherited.stderr
new file mode 100644
index 000000000..3bc5ca5c9
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-not-inherited.stderr
@@ -0,0 +1,24 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-not-inherited.rs:6:31
+ |
+LL | unsafe {static BAR: u64 = FOO;}
+ | ------ ^^^ use of mutable static
+ | |
+ | items do not inherit unsafety from separate enclosing items
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
+ --> $DIR/unsafe-not-inherited.rs:18:13
+ |
+LL | unsafe {
+ | ------ items do not inherit unsafety from separate enclosing items
+...
+LL | unsafe_call();
+ | ^^^^^^^^^^^^^ call to unsafe function
+ |
+ = note: consult the function's documentation for information on how to avoid undefined behavior
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0133`.