Skip to content

Commit 76c5229

Browse files
committed
Document purpose of union-nonzero test
1 parent 48d1be4 commit 76c5229

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/test/run-pass/union/union-nonzero.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
// run-pass
22
#![allow(dead_code)]
33

4+
// Tests that unions aren't subject to unsafe non-zero/niche-filling optimizations.
5+
//
6+
// For example, if a union `U` can contain both a `&T` and a `*const T`, there's definitely no
7+
// bit-value that an `Option<U>` could reuse as `None`; this test makes sure that isn't done.
8+
//
9+
// Secondly, this tests the status quo to not apply such optimizations to types containing unions
10+
// even if they're theoretically possible. (discussion: https://github.com/rust-lang/rust/issues/36394)
11+
//
12+
// Notably this nails down part of the behavior that `MaybeUninit` assumes: that a
13+
// `Option<MaybeUninit<&u8>>` does not take advantage of non-zero optimization, and thus is a safe
14+
// construct.
15+
416
use std::mem::{size_of, transmute};
517

618
union U1<A: Copy> {

0 commit comments

Comments
 (0)