about summary refs log tree commit diff
path: root/tests/ui/statics/mutable_memory_validation.rs
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-03-26 09:35:38 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-04-17 09:50:15 +0000
commit8c9cba2be7c6c61ef91d722d27a55abb5eef371c (patch)
treeb0040d19fdd43a4d3cd967ee558614979214e48d /tests/ui/statics/mutable_memory_validation.rs
parent6c6b3027ef62e911142cfc55589baef4e9f38ec8 (diff)
downloadrust-8c9cba2be7c6c61ef91d722d27a55abb5eef371c.tar.gz
rust-8c9cba2be7c6c61ef91d722d27a55abb5eef371c.zip
Validate nested static items
Diffstat (limited to 'tests/ui/statics/mutable_memory_validation.rs')
-rw-r--r--tests/ui/statics/mutable_memory_validation.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/ui/statics/mutable_memory_validation.rs b/tests/ui/statics/mutable_memory_validation.rs
new file mode 100644
index 00000000000..fcf6ad16277
--- /dev/null
+++ b/tests/ui/statics/mutable_memory_validation.rs
@@ -0,0 +1,21 @@
+//issue: rust-lang/rust#122548
+
+// Strip out raw byte dumps to make comparison platform-independent:
+//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
+//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
+
+#![feature(const_mut_refs)]
+#![feature(const_refs_to_static)]
+
+use std::cell::UnsafeCell;
+
+struct Meh {
+    x: &'static UnsafeCell<i32>,
+}
+
+const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
+//~^ ERROR: it is undefined behavior to use this value
+
+static READONLY: i32 = 0;
+
+pub fn main() {}