about summary refs log tree commit diff
path: root/tests/ui/unsafe
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-07-01 23:33:59 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-07-01 23:33:59 +0500
commit1fb5e0149fb85af0e49fa40329cbc352b4cba861 (patch)
tree99717c06e20c4557a9e4d756a13bbf88d8093966 /tests/ui/unsafe
parentf46ce66fcc3d6058f90ac5bf0930f940f1e7b0ca (diff)
downloadrust-1fb5e0149fb85af0e49fa40329cbc352b4cba861.tar.gz
rust-1fb5e0149fb85af0e49fa40329cbc352b4cba861.zip
moved tests
Diffstat (limited to 'tests/ui/unsafe')
-rw-r--r--tests/ui/unsafe/maybe-uninit-zero-sized-types.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/ui/unsafe/maybe-uninit-zero-sized-types.rs b/tests/ui/unsafe/maybe-uninit-zero-sized-types.rs
new file mode 100644
index 00000000000..82474d873b7
--- /dev/null
+++ b/tests/ui/unsafe/maybe-uninit-zero-sized-types.rs
@@ -0,0 +1,18 @@
+//@ build-pass
+// Test the uninit() construct returning various empty types.
+
+
+use std::mem::MaybeUninit;
+
+struct Foo;
+
+#[allow(deprecated)]
+pub fn main() {
+    unsafe {
+        // `Foo` and `[Foo; 2]` are both zero sized and inhabited, so this is safe.
+        let _x: Foo = MaybeUninit::uninit().assume_init();
+        let _x: [Foo; 2] = MaybeUninit::uninit().assume_init();
+        let _x: Foo = std::mem::uninitialized();
+        let _x: [Foo; 2] = std::mem::uninitialized();
+    }
+}