about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-02-11 01:37:56 +0100
committerGitHub <noreply@github.com>2024-02-11 01:37:56 +0100
commit09bbcd6667631e31c63e9f8d1c930e2bab5ebeb3 (patch)
tree3dd2836d5ffdfc3c422abb9c54688f5c06842fea /tests/ui
parente82e087582112a4a6082afc9b826392438a8b324 (diff)
parentd56f3b6a5ddbdf6af0c2fb6b7a8327d698e2e228 (diff)
downloadrust-09bbcd6667631e31c63e9f8d1c930e2bab5ebeb3.tar.gz
rust-09bbcd6667631e31c63e9f8d1c930e2bab5ebeb3.zip
Rollup merge of #120883 - RalfJung:extern-static-err, r=oli-obk
interpret: rename ReadExternStatic → ExternStatic

This error shows up for reads and writes, so `ReadExternStatic` is misleading.
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/consts/miri_unleashed/extern-static.rs24
-rw-r--r--tests/ui/consts/miri_unleashed/extern-static.stderr15
-rw-r--r--tests/ui/consts/miri_unleashed/tls.rs2
-rw-r--r--tests/ui/consts/miri_unleashed/tls.stderr4
4 files changed, 43 insertions, 2 deletions
diff --git a/tests/ui/consts/miri_unleashed/extern-static.rs b/tests/ui/consts/miri_unleashed/extern-static.rs
new file mode 100644
index 00000000000..81176b3d4e9
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/extern-static.rs
@@ -0,0 +1,24 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(thread_local)]
+#![allow(static_mut_ref)]
+
+extern "C" {
+    static mut DATA: u8;
+}
+
+// Make sure we catch accessing extern static.
+static TEST_READ: () = {
+    unsafe { let _val = DATA; }
+    //~^ ERROR could not evaluate static initializer
+    //~| NOTE cannot access extern static
+};
+static TEST_WRITE: () = {
+    unsafe { DATA = 0; }
+    //~^ ERROR could not evaluate static initializer
+    //~| NOTE cannot access extern static
+};
+
+// Just creating a reference is fine, as long as we are not reading or writing.
+static TEST_REF: &u8 = unsafe { &DATA };
+
+fn main() {}
diff --git a/tests/ui/consts/miri_unleashed/extern-static.stderr b/tests/ui/consts/miri_unleashed/extern-static.stderr
new file mode 100644
index 00000000000..0979a5e4fb1
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/extern-static.stderr
@@ -0,0 +1,15 @@
+error[E0080]: could not evaluate static initializer
+  --> $DIR/extern-static.rs:11:25
+   |
+LL |     unsafe { let _val = DATA; }
+   |                         ^^^^ cannot access extern static (DefId(0:4 ~ extern_static[c41e]::{extern#0}::DATA))
+
+error[E0080]: could not evaluate static initializer
+  --> $DIR/extern-static.rs:16:14
+   |
+LL |     unsafe { DATA = 0; }
+   |              ^^^^^^^^ cannot access extern static (DefId(0:4 ~ extern_static[c41e]::{extern#0}::DATA))
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/miri_unleashed/tls.rs b/tests/ui/consts/miri_unleashed/tls.rs
index d06d7cf19f7..7319a5135d3 100644
--- a/tests/ui/consts/miri_unleashed/tls.rs
+++ b/tests/ui/consts/miri_unleashed/tls.rs
@@ -14,6 +14,8 @@ static TEST_BAD: () = {
 };
 
 // Make sure we catch taking a reference to thread-local storage.
+// The actual pointer depends on the thread, so even just taking a reference already does not make
+// sense at compile-time.
 static TEST_BAD_REF: () = {
     unsafe { let _val = &A; }
     //~^ ERROR could not evaluate static initializer
diff --git a/tests/ui/consts/miri_unleashed/tls.stderr b/tests/ui/consts/miri_unleashed/tls.stderr
index ec24527d6c0..a00b7eb1312 100644
--- a/tests/ui/consts/miri_unleashed/tls.stderr
+++ b/tests/ui/consts/miri_unleashed/tls.stderr
@@ -5,7 +5,7 @@ LL |     unsafe { let _val = A; }
    |                         ^ cannot access thread local static (DefId(0:4 ~ tls[ca29]::A))
 
 error[E0080]: could not evaluate static initializer
-  --> $DIR/tls.rs:18:26
+  --> $DIR/tls.rs:20:26
    |
 LL |     unsafe { let _val = &A; }
    |                          ^ cannot access thread local static (DefId(0:4 ~ tls[ca29]::A))
@@ -18,7 +18,7 @@ help: skipping check that does not even have a feature gate
 LL |     unsafe { let _val = A; }
    |                         ^
 help: skipping check that does not even have a feature gate
-  --> $DIR/tls.rs:18:26
+  --> $DIR/tls.rs:20:26
    |
 LL |     unsafe { let _val = &A; }
    |                          ^