about summary refs log tree commit diff
path: root/tests/ui/statics
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-06-16 10:35:59 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-06-20 06:20:22 +0000
commite159cf0c9e943c7f9b95f7c931abc825ee33f958 (patch)
tree0807045d2739776bfa85cb08298ab8125cde0e24 /tests/ui/statics
parent5b74275f89b6041bf2e9dc2abcf332e206d4cfca (diff)
downloadrust-e159cf0c9e943c7f9b95f7c931abc825ee33f958.tar.gz
rust-e159cf0c9e943c7f9b95f7c931abc825ee33f958.zip
Add regression test
Diffstat (limited to 'tests/ui/statics')
-rw-r--r--tests/ui/statics/read_before_init.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/ui/statics/read_before_init.rs b/tests/ui/statics/read_before_init.rs
new file mode 100644
index 00000000000..02af783063a
--- /dev/null
+++ b/tests/ui/statics/read_before_init.rs
@@ -0,0 +1,15 @@
+//@ check-pass
+
+use std::mem::MaybeUninit;
+
+pub static X: (i32, MaybeUninit<i32>) = (1, foo(&X.0));
+
+const fn foo(x: &i32) -> MaybeUninit<i32> {
+    let mut temp = MaybeUninit::<i32>::uninit();
+    unsafe {
+        std::ptr::copy(x, temp.as_mut_ptr(), 1);
+    }
+    temp
+}
+
+fn main() {}