Add non-non-zero test to union-nonzero test

This commit is contained in:
Peter Todd 2019-05-07 12:17:28 -04:00
parent 76c5229021
commit aa1db2476a
No known key found for this signature in database
GPG Key ID: 2481403DA5F091FB

View File

@ -24,10 +24,18 @@ union U2<A: Copy, B: Copy> {
b: B,
}
// Option<E> uses a value other than 0 and 1 as None
#[derive(Clone,Copy)]
enum E {
A = 0,
B = 1,
}
fn main() {
// Unions do not participate in niche-filling/non-zero optimization...
assert!(size_of::<Option<U2<&u8, u8>>>() > size_of::<U2<&u8, u8>>());
assert!(size_of::<Option<U2<&u8, ()>>>() > size_of::<U2<&u8, ()>>());
assert!(size_of::<Option<U2<u8, E>>>() > size_of::<U2<u8, E>>());
// ...even when theoretically possible:
assert!(size_of::<Option<U1<&u8>>>() > size_of::<U1<&u8>>());