Skip to content

Commit 46ff257

Browse files
committed
test that partially uninit MaybeUninit works correctly
1 parent 955bacc commit 46ff257

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-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

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

0 commit comments

Comments
 (0)