7 // cdb-check:a : Some [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
8 // cdb-check: [+0x000] __0 : Low (0x2) [Type: msvc_pretty_enums::CStyleEnum]
11 // cdb-check:b : None [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
14 // cdb-check:c : Tag1 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
17 // cdb-check:d : Data [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
18 // cdb-check: [+0x000] my_data : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
21 // cdb-check:e : Tag2 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
24 // cdb-check:f : Some [Type: enum2$<core::option::Option<ref$<u32> > >]
25 // cdb-check: [+0x000] __0 : 0x[...] : 0x1 [Type: unsigned int *]
28 // cdb-check:g : None [Type: enum2$<core::option::Option<ref$<u32> > >]
31 // cdb-check:h : Some [Type: enum2$<core::option::Option<u32> >]
32 // cdb-check: [+0x004] __0 : 0xc [Type: unsigned int]
35 // cdb-check:i : None [Type: enum2$<core::option::Option<u32> >]
38 // cdb-check:j : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
41 // cdb-check:k : Some [Type: enum2$<core::option::Option<alloc::string::String> >]
42 // cdb-check: [+0x000] __0 : "IAMA optional string!" [Type: alloc::string::String]
45 // cdb-check:l : Ok [Type: enum2$<core::result::Result<u32,enum2$<msvc_pretty_enums::Empty> > >]
46 // cdb-check: [+0x000] __0 : 0x2a [Type: unsigned int]
48 // cdb-command: dx niche128_some
49 // cdb-check: niche128_some : Some [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
50 // Note: we can't actually read the value of the field because CDB cannot handle 128 bit integers.
51 // cdb-check: [+0x000] __0 [...] [Type: core::num::nonzero::NonZeroI128]
53 // cdb-command: dx niche128_none
54 // cdb-check: niche128_none : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
56 // cdb-command: dx wrapping_niche128_dataful
57 // cdb-check: wrapping_niche128_dataful : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
58 // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
60 // cdb-command: dx wrapping_niche128_none1
61 // cdb-check: wrapping_niche128_none1 : Y [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
62 // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
64 // cdb-command: dx wrapping_niche128_none2
65 // cdb-check: wrapping_niche128_none2 : Z [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
66 // cdb-check: [+0x[...]] __0 [Type: msvc_pretty_enums::Wrapping128]
68 // cdb-command: dx direct_tag_128_a,d
69 // cdb-check: direct_tag_128_a,d : A [Type: enum2$<msvc_pretty_enums::DirectTag128>]
70 // cdb-check: [+0x[...]] __0 : 42 [Type: unsigned int]
72 // cdb-command: dx direct_tag_128_b,d
73 // cdb-check: direct_tag_128_b,d : B [Type: enum2$<msvc_pretty_enums::DirectTag128>]
74 // cdb-check: [+0x[...]] __0 : 137 [Type: unsigned int]
76 // cdb-command: dx niche_w_fields_1_some,d
77 // cdb-check: niche_w_fields_1_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>]
78 // cdb-check: [+0x[...]] __0 : 0x[...] : 77 [Type: unsigned char *]
79 // cdb-check: [+0x[...]] __1 : 7 [Type: unsigned int]
81 // cdb-command: dx niche_w_fields_1_none,d
82 // cdb-check: niche_w_fields_1_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields1>]
83 // cdb-check: [+0x[...]] __0 : 99 [Type: unsigned int]
85 // cdb-command: dx niche_w_fields_2_some,d
86 // cdb-check: niche_w_fields_2_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
87 // cdb-check: [+0x[...]] __0 : 800 [Type: core::num::nonzero::NonZeroU32]
88 // cdb-check: [+0x[...]] __1 : 900 [Type: unsigned __int64]
90 // cdb-command: dx niche_w_fields_2_none,d
91 // cdb-check: niche_w_fields_2_none,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields2>]
92 // cdb-check: [+0x[...]] __0 : 1000 [Type: unsigned __int64]
94 // cdb-command: dx niche_w_fields_3_some,d
95 // cdb-check: niche_w_fields_3_some,d : A [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
96 // cdb-check: [+0x[...]] __0 : 137 [Type: unsigned char]
97 // cdb-check: [+0x[...]] __1 : true [Type: bool]
99 // cdb-command: dx niche_w_fields_3_niche1,d
100 // cdb-check: niche_w_fields_3_niche1,d : B [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
101 // cdb-check: [+0x[...]] __0 : 12 [Type: unsigned char]
103 // cdb-command: dx niche_w_fields_3_niche2,d
104 // cdb-check: niche_w_fields_3_niche2,d : C [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
105 // cdb-check: [+0x[...]] __0 : false [Type: bool]
107 // cdb-command: dx niche_w_fields_3_niche3,d
108 // cdb-check: niche_w_fields_3_niche3,d : D [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
109 // cdb-check: [+0x[...]] __0 : 34 [Type: unsigned char]
111 // cdb-command: dx niche_w_fields_3_niche4,d
112 // cdb-check: niche_w_fields_3_niche4,d : E [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
113 // cdb-check: [+0x[...]] __0 : 56 [Type: unsigned char]
115 // cdb-command: dx niche_w_fields_3_niche5,d
116 // cdb-check: niche_w_fields_3_niche5,d : F [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
118 // cdb-command: dx -r3 niche_w_fields_std_result_ok,d
119 // cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
120 // cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>]
121 // cdb-check: [+0x[...]] data_ptr : [...]
122 // cdb-check: [+0x[...]] length : 3 [...]
124 // cdb-command: dx -r3 niche_w_fields_std_result_err,d
125 // cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
126 // cdb-check: [+0x[...]] __0 : 789 [Type: unsigned __int64]
128 // cdb-command: dx -r2 arbitrary_discr1,d
129 // cdb-check: arbitrary_discr1,d : Abc [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>]
130 // cdb-check: [+0x[...]] __0 : 1234 [Type: unsigned int]
132 // cdb-command: dx -r2 arbitrary_discr2,d
133 // cdb-check: arbitrary_discr2,d : Def [Type: enum2$<msvc_pretty_enums::ArbitraryDiscr>]
134 // cdb-check: [+0x[...]] __0 : 5678 [Type: unsigned int]
136 #![feature(rustc_attrs)]
138 #![feature(arbitrary_enum_discriminant)]
140 use std::num::{NonZeroI128, NonZeroU32};
142 pub enum CStyleEnum {
147 pub enum NicheLayoutEnum {
149 Data { my_data: CStyleEnum },
155 // The following three types will use a niche layout once
156 // https://github.com/rust-lang/rust/pull/94075 is merged:
157 enum NicheLayoutWithFields1<'a> {
162 enum NicheLayoutWithFields2 {
163 A(NonZeroU32, usize),
167 enum NicheLayoutWithFields3 {
176 #[rustc_layout_scalar_valid_range_start(340282366920938463463374607431768211454)]
177 #[rustc_layout_scalar_valid_range_end(1)]
179 struct Wrapping128(u128);
181 // #[rustc_layout(debug)]
182 enum Wrapping128Niche {
195 enum ArbitraryDiscr {
201 let a = Some(CStyleEnum::Low);
202 let b = Option::<CStyleEnum>::None;
203 let c = NicheLayoutEnum::Tag1;
204 let d = NicheLayoutEnum::Data { my_data: CStyleEnum::High };
205 let e = NicheLayoutEnum::Tag2;
207 let g = Option::<&'static u32>::None;
209 let i = Option::<u32>::None;
210 let j = CStyleEnum::High;
211 let k = Some("IAMA optional string!".to_string());
212 let l = Result::<u32, Empty>::Ok(42);
213 let niche128_some = Some(NonZeroI128::new(123456).unwrap());
214 let niche128_none: Option<NonZeroI128> = None;
216 let wrapping_niche128_dataful =
217 unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) };
218 let wrapping_niche128_none1 = Wrapping128Niche::Y;
219 let wrapping_niche128_none2 = Wrapping128Niche::Z;
221 let direct_tag_128_a = DirectTag128::A(42);
222 let direct_tag_128_b = DirectTag128::B(137);
224 let niche_w_fields_1_some = NicheLayoutWithFields1::A(&77, 7);
225 let niche_w_fields_1_none = NicheLayoutWithFields1::B(99);
227 let niche_w_fields_2_some = NicheLayoutWithFields2::A(NonZeroU32::new(800).unwrap(), 900);
228 let niche_w_fields_2_none = NicheLayoutWithFields2::B(1000);
230 let niche_w_fields_3_some = NicheLayoutWithFields3::A(137, true);
231 let niche_w_fields_3_niche1 = NicheLayoutWithFields3::B(12);
232 let niche_w_fields_3_niche2 = NicheLayoutWithFields3::C(false);
233 let niche_w_fields_3_niche3 = NicheLayoutWithFields3::D(34);
234 let niche_w_fields_3_niche4 = NicheLayoutWithFields3::E(56);
235 let niche_w_fields_3_niche5 = NicheLayoutWithFields3::F;
237 let niche_w_fields_std_result_ok: Result<Box<[u8]>, u64> = Ok(vec![1, 2, 3].into());
238 let niche_w_fields_std_result_err: Result<Box<[u8]>, u64> = Err(789);
240 let arbitrary_discr1 = ArbitraryDiscr::Abc(1234);
241 let arbitrary_discr2 = ArbitraryDiscr::Def(5678);