]> git.lizzy.rs Git - rust.git/blob - tests/debuginfo/msvc-pretty-enums.rs
Merge commit '7d53619064ab7045c383644cb445052d2a3d46db' into sync_cg_clif-2023-02-09
[rust.git] / tests / debuginfo / msvc-pretty-enums.rs
1 // only-cdb
2 // compile-flags:-g
3
4 // cdb-command: g
5
6 // cdb-command: dx a
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]
9
10 // cdb-command: dx b
11 // cdb-check:b                : None [Type: enum2$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
12
13 // cdb-command: dx c
14 // cdb-check:c                : Tag1 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
15
16 // cdb-command: dx d
17 // cdb-check:d                : Data [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
18 // cdb-check:    [+0x000] my_data          : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
19
20 // cdb-command: dx e
21 // cdb-check:e                : Tag2 [Type: enum2$<msvc_pretty_enums::NicheLayoutEnum>]
22
23 // cdb-command: dx f
24 // cdb-check:f                : Some [Type: enum2$<core::option::Option<ref$<u32> > >]
25 // cdb-check:    [+0x000] __0              : 0x[...] : 0x1 [Type: unsigned int *]
26
27 // cdb-command: dx g
28 // cdb-check:g                : None [Type: enum2$<core::option::Option<ref$<u32> > >]
29
30 // cdb-command: dx h
31 // cdb-check:h                : Some [Type: enum2$<core::option::Option<u32> >]
32 // cdb-check:    [+0x004] __0              : 0xc [Type: unsigned int]
33
34 // cdb-command: dx i
35 // cdb-check:i                : None [Type: enum2$<core::option::Option<u32> >]
36
37 // cdb-command: dx j
38 // cdb-check:j                : High (0x10) [Type: msvc_pretty_enums::CStyleEnum]
39
40 // cdb-command: dx k
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]
43
44 // cdb-command: dx l
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]
47
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]
52
53 // cdb-command: dx niche128_none
54 // cdb-check: niche128_none    : None [Type: enum2$<core::option::Option<core::num::nonzero::NonZeroI128> >]
55
56 // cdb-command: dx wrapping_niche128_untagged
57 // cdb-check: wrapping_niche128_untagged : X [Type: enum2$<msvc_pretty_enums::Wrapping128Niche>]
58 // cdb-check:    [+0x[...]] __0              [Type: msvc_pretty_enums::Wrapping128]
59
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]
63
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]
67
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]
71
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]
75
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]
80
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]
84
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]
89
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]
93
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]
98
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]
102
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]
106
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]
110
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]
114
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>]
117
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<slice2$<u8>,alloc::alloc::Global>,u64> >]
120 // cdb-check:    [+0x[...]] __0              [Type: alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>]
121 // cdb-check:        [+0x[...]] data_ptr         : [...]
122 // cdb-check:        [+0x[...]] length           : 3 [...]
123
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<slice2$<u8>,alloc::alloc::Global>,u64> >]
126 // cdb-check:    [+0x[...]] __0              : 789 [Type: unsigned __int64]
127
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]
131
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]
135
136 #![feature(rustc_attrs)]
137 #![feature(repr128)]
138 #![feature(arbitrary_enum_discriminant)]
139
140 use std::num::{NonZeroI128, NonZeroU32};
141
142 pub enum CStyleEnum {
143     Low = 2,
144     High = 16,
145 }
146
147 pub enum NicheLayoutEnum {
148     Tag1,
149     Data { my_data: CStyleEnum },
150     Tag2,
151 }
152
153 pub enum Empty {}
154
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> {
158     A(&'a u8, u32),
159     B(u32),
160 }
161
162 enum NicheLayoutWithFields2 {
163     A(NonZeroU32, u64),
164     B(u64),
165 }
166
167 enum NicheLayoutWithFields3 {
168     A(u8, bool),
169     B(u8),
170     C(bool),
171     D(u8),
172     E(u8),
173     F,
174 }
175
176 #[rustc_layout_scalar_valid_range_start(340282366920938463463374607431768211454)]
177 #[rustc_layout_scalar_valid_range_end(1)]
178 #[repr(transparent)]
179 struct Wrapping128(u128);
180
181 // #[rustc_layout(debug)]
182 enum Wrapping128Niche {
183     X(Wrapping128),
184     Y,
185     Z,
186 }
187
188 #[repr(i128)]
189 enum DirectTag128 {
190     A(u32),
191     B(u32),
192 }
193
194 #[repr(u32)]
195 enum ArbitraryDiscr {
196     Abc(u32) = 1000,
197     Def(u32) = 5000_000,
198 }
199
200 fn main() {
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;
206     let f = Some(&1u32);
207     let g = Option::<&'static u32>::None;
208     let h = Some(12u32);
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;
215
216     let wrapping_niche128_untagged =
217         unsafe { Wrapping128Niche::X(Wrapping128(340282366920938463463374607431768211454)) };
218     let wrapping_niche128_none1 = Wrapping128Niche::Y;
219     let wrapping_niche128_none2 = Wrapping128Niche::Z;
220
221     let direct_tag_128_a = DirectTag128::A(42);
222     let direct_tag_128_b = DirectTag128::B(137);
223
224     let niche_w_fields_1_some = NicheLayoutWithFields1::A(&77, 7);
225     let niche_w_fields_1_none = NicheLayoutWithFields1::B(99);
226
227     let niche_w_fields_2_some = NicheLayoutWithFields2::A(NonZeroU32::new(800).unwrap(), 900);
228     let niche_w_fields_2_none = NicheLayoutWithFields2::B(1000);
229
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;
236
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);
239
240     let arbitrary_discr1 = ArbitraryDiscr::Abc(1234);
241     let arbitrary_discr2 = ArbitraryDiscr::Def(5678);
242
243     zzz(); // #break
244 }
245
246 fn zzz() {
247     ()
248 }