summaryrefslogtreecommitdiffstats
path: root/library/core/tests/mem.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /library/core/tests/mem.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/tests/mem.rs')
-rw-r--r--library/core/tests/mem.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs
index 5c2e18745..20498b16c 100644
--- a/library/core/tests/mem.rs
+++ b/library/core/tests/mem.rs
@@ -565,3 +565,24 @@ fn offset_of_addr() {
assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, z.0), ptr::addr_of!(base.z.0).addr());
assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, z.1), ptr::addr_of!(base.z.1).addr());
}
+
+#[test]
+fn const_maybe_uninit_zeroed() {
+ // Sanity check for `MaybeUninit::zeroed` in a realistic const situation (plugin array term)
+ #[repr(C)]
+ struct Foo {
+ a: Option<&'static str>,
+ b: Bar,
+ c: f32,
+ d: *const u8,
+ }
+ #[repr(C)]
+ struct Bar(usize);
+ struct FooPtr(*const Foo);
+ unsafe impl Sync for FooPtr {}
+
+ static UNINIT: FooPtr = FooPtr([unsafe { MaybeUninit::zeroed().assume_init() }].as_ptr());
+ const SIZE: usize = size_of::<Foo>();
+
+ assert_eq!(unsafe { (*UNINIT.0.cast::<[[u8; SIZE]; 1]>())[0] }, [0u8; SIZE]);
+}