Skip to content

Commit 357d26c

Browse files
committed
test that partially uninit MaybeUninit works correctly
1 parent 955bacc commit 357d26c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
634770c0a7f8598164ab825cfe419cc8b03c36e5
1+
f262ca12aac76152c4b46cefcf8300f0249a5eb2

tests/run-pass/partially-uninit.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::mem::{self, MaybeUninit};
2+
3+
#[repr(C)]
4+
#[derive(Copy, Clone, Debug, PartialEq)]
5+
struct Demo(bool, u16);
6+
7+
fn main() { unsafe {
8+
// Transmute-round-trip through a type with Scalar layout is lossless.
9+
// This is tricky because that 'scalar' is *partially* uninitialized.
10+
let x = Demo(true, 3);
11+
let y: MaybeUninit<u32> = mem::transmute(x);
12+
assert_eq!(x, mem::transmute(y));
13+
} }

0 commit comments

Comments
 (0)