Skip to content

Commit fb01df5

Browse files
committed
Auto merge of #2050 - RalfJung:partially-uninit, r=RalfJung
test that partially uninit MaybeUninit works correctly This got finally fixed by rust-lang/rust#94527 :)
2 parents 955bacc + 46ff257 commit fb01df5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
634770c0a7f8598164ab825cfe419cc8b03c36e5
1+
f262ca12aac76152c4b46cefcf8300f0249a5eb2

tests/run-pass/partially-uninit.rs

Lines changed: 15 additions & 0 deletions
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)