1 // compile-flags: -Z print-type-sizes
4 // This file illustrates how niche-filling enums are handled,
5 // modelled after cases like `Option<&u32>`, `Option<bool>` and such.
7 // It uses NonZeroU32 rather than `&_` or `Unique<_>`, because
8 // the test is not set up to deal with target-dependent pointer width.
10 // It avoids using u64/i64 because on some targets that is only 4-byte
11 // aligned (while on most it is 8-byte aligned) and so the resulting
12 // padding and overall computed sizes can be quite different.
17 use std::num::NonZeroU32;
19 pub enum MyOption<T> { None, Some(T) }
21 impl<T> Default for MyOption<T> {
22 fn default() -> Self { MyOption::None }
25 pub enum EmbeddedDiscr {
27 Record { pre: u8, val: NonZeroU32, post: u16 },
30 impl Default for EmbeddedDiscr {
31 fn default() -> Self { EmbeddedDiscr::None }
35 pub struct IndirectNonZero {
37 nested: NestedNonZero,
41 pub struct NestedNonZero {
47 impl Default for NestedNonZero {
48 fn default() -> Self {
49 NestedNonZero { pre: 0, val: NonZeroU32::new(1).unwrap(), post: 0 }
53 pub enum Enum4<A, B, C, D> {
61 fn start(_: isize, _: *const *const u8) -> isize {
62 let _x: MyOption<NonZeroU32> = Default::default();
63 let _y: EmbeddedDiscr = Default::default();
64 let _z: MyOption<IndirectNonZero> = Default::default();
65 let _a: MyOption<bool> = Default::default();
66 let _b: MyOption<char> = Default::default();
67 let _c: MyOption<std::cmp::Ordering> = Default::default();
68 let _b: MyOption<MyOption<u8>> = Default::default();
69 let _e: Enum4<(), char, (), ()> = Enum4::One(());
70 let _f: Enum4<(), (), bool, ()> = Enum4::One(());
71 let _g: Enum4<(), (), (), MyOption<u8>> = Enum4::One(());