]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/msvc-pretty-enums.rs
debuginfo: Change C++-like encoding for enums.
[rust.git] / src / test / 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: enum$<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: enum$<core::option::Option<msvc_pretty_enums::CStyleEnum> >]
12
13 // cdb-command: dx c
14 // cdb-check:c                : Tag1 [Type: enum$<msvc_pretty_enums::NicheLayoutEnum>]
15
16 // cdb-command: dx d
17 // cdb-check:d                : Data [Type: enum$<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: enum$<msvc_pretty_enums::NicheLayoutEnum>]
22
23 // cdb-command: dx f
24 // cdb-check:f                : Some [Type: enum$<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: enum$<core::option::Option<ref$<u32> > >]
29
30 // cdb-command: dx h
31 // cdb-check:h                : Some [Type: enum$<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: enum$<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: enum$<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: enum$<core::result::Result<u32,enum$<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: enum$<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: enum$<core::option::Option<core::num::nonzero::NonZeroI128> >]
55
56 // cdb-command: dx niche_w_fields_1_some,d
57 // cdb-check: niche_w_fields_1_some,d : A [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields1>]
58 // cdb-check:     [+0x[...]] __0              : 0x[...] : 77 [Type: unsigned char *]
59 // cdb-check:     [+0x[...]] __1              : 7 [Type: unsigned int]
60
61 // cdb-command: dx niche_w_fields_1_none,d
62 // cdb-check: niche_w_fields_1_none,d : B [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields1>]
63 // cdb-check:     [+0x[...]] __0              : 99 [Type: unsigned int]
64
65 // cdb-command: dx niche_w_fields_2_some,d
66 // cdb-check: niche_w_fields_2_some,d : A [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields2>]
67 // cdb-check:     [<Raw View>]     [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields2>]
68 // cdb-check:     [+0x[...]] __0              : 800 [Type: core::num::nonzero::NonZeroU32]
69 // cdb-check:     [+0x[...]] __1              : 900 [Type: unsigned __int64]
70
71 // cdb-command: dx niche_w_fields_2_none,d
72 // cdb-check: niche_w_fields_2_none,d : B [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields2>]
73 // cdb-check:     [+0x[...]] __0              : 1000 [Type: unsigned __int64]
74
75 // cdb-command: dx niche_w_fields_3_some,d
76 // cdb-check: niche_w_fields_3_some,d : A [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
77 // cdb-check:     [+0x[...]] __0              : 137 [Type: unsigned char]
78 // cdb-check:     [+0x[...]] __1              : true [Type: bool]
79
80 // cdb-command: dx niche_w_fields_3_niche1,d
81 // cdb-check: niche_w_fields_3_niche1,d : B [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
82 // cdb-check:     [+0x[...]] __0              : 12 [Type: unsigned char]
83
84 // cdb-command: dx niche_w_fields_3_niche2,d
85 // cdb-check: niche_w_fields_3_niche2,d : C [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
86 // cdb-check:     [+0x[...]] __0              : false [Type: bool]
87
88 // cdb-command: dx niche_w_fields_3_niche3,d
89 // cdb-check: niche_w_fields_3_niche3,d : D [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
90 // cdb-check:     [+0x[...]] __0              : 34 [Type: unsigned char]
91
92 // cdb-command: dx niche_w_fields_3_niche4,d
93 // cdb-check: niche_w_fields_3_niche4,d : E [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
94 // cdb-check:     [+0x[...]] __0              : 56 [Type: unsigned char]
95
96 // cdb-command: dx niche_w_fields_3_niche5,d
97 // cdb-check: niche_w_fields_3_niche5,d : F [Type: enum$<msvc_pretty_enums::NicheLayoutWithFields3>]
98
99 // cdb-command: dx -r3 niche_w_fields_std_result_ok,d
100 // cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
101 // cdb-check:    [+0x[...]] __0              [Type: alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>]
102 // cdb-check:        [+0x[...]] data_ptr         : [...]
103 // cdb-check:        [+0x[...]] length           : 3 [...]
104
105 // cdb-command: dx -r3 niche_w_fields_std_result_err,d
106 // cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
107 // cdb-check:    [+0x[...]] __0              : 789 [Type: unsigned __int64]
108
109 use std::num::{NonZeroI128, NonZeroU32};
110
111 pub enum CStyleEnum {
112     Low = 2,
113     High = 16,
114 }
115
116 pub enum NicheLayoutEnum {
117     Tag1,
118     Data { my_data: CStyleEnum },
119     Tag2,
120 }
121
122 pub enum Empty {}
123
124 // The following three types will use a niche layout once
125 // https://github.com/rust-lang/rust/pull/94075 is merged:
126 enum NicheLayoutWithFields1<'a> {
127     A(&'a u8, u32),
128     B(u32),
129 }
130
131 enum NicheLayoutWithFields2 {
132     A(NonZeroU32, usize),
133     B(usize),
134 }
135
136 enum NicheLayoutWithFields3 {
137     A(u8, bool),
138     B(u8),
139     C(bool),
140     D(u8),
141     E(u8),
142     F,
143 }
144
145 fn main() {
146     let a = Some(CStyleEnum::Low);
147     let b = Option::<CStyleEnum>::None;
148     let c = NicheLayoutEnum::Tag1;
149     let d = NicheLayoutEnum::Data { my_data: CStyleEnum::High };
150     let e = NicheLayoutEnum::Tag2;
151     let f = Some(&1u32);
152     let g = Option::<&'static u32>::None;
153     let h = Some(12u32);
154     let i = Option::<u32>::None;
155     let j = CStyleEnum::High;
156     let k = Some("IAMA optional string!".to_string());
157     let l = Result::<u32, Empty>::Ok(42);
158     let niche128_some = Some(NonZeroI128::new(123456).unwrap());
159     let niche128_none: Option<NonZeroI128> = None;
160
161     let niche_w_fields_1_some = NicheLayoutWithFields1::A(&77, 7);
162     let niche_w_fields_1_none = NicheLayoutWithFields1::B(99);
163
164     let niche_w_fields_2_some = NicheLayoutWithFields2::A(NonZeroU32::new(800).unwrap(), 900);
165     let niche_w_fields_2_none = NicheLayoutWithFields2::B(1000);
166
167     let niche_w_fields_3_some = NicheLayoutWithFields3::A(137, true);
168     let niche_w_fields_3_niche1 = NicheLayoutWithFields3::B(12);
169     let niche_w_fields_3_niche2 = NicheLayoutWithFields3::C(false);
170     let niche_w_fields_3_niche3 = NicheLayoutWithFields3::D(34);
171     let niche_w_fields_3_niche4 = NicheLayoutWithFields3::E(56);
172     let niche_w_fields_3_niche5 = NicheLayoutWithFields3::F;
173
174     let niche_w_fields_std_result_ok: Result<Box<[u8]>, u64> = Ok(vec![1, 2, 3].into());
175     let niche_w_fields_std_result_err: Result<Box<[u8]>, u64> = Err(789);
176
177     zzz(); // #break
178 }
179
180 fn zzz() {
181     ()
182 }