]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/option-like-enum.rs
Auto merge of #68528 - ecstatic-morse:maybe-init-variants, r=oli-obk
[rust.git] / src / test / debuginfo / option-like-enum.rs
1 // ignore-tidy-linelength
2 // ignore-test // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155
3
4 // min-lldb-version: 310
5
6 // compile-flags:-g
7
8 // === GDB TESTS ===================================================================================
9
10 // gdb-command:run
11
12 // gdb-command:print some
13 // gdbg-check:$1 = {RUST$ENCODED$ENUM$0$None = {__0 = 0x12345678}}
14 // gdbr-check:$1 = core::option::Option<&u32>::Some(0x12345678)
15
16 // gdb-command:print none
17 // gdbg-check:$2 = {RUST$ENCODED$ENUM$0$None = {__0 = 0x0}}
18 // gdbr-check:$2 = core::option::Option<&u32>::None
19
20 // gdb-command:print full
21 // gdbg-check:$3 = {RUST$ENCODED$ENUM$1$Empty = {__0 = 454545, __1 = 0x87654321, __2 = 9988}}
22 // gdbr-check:$3 = option_like_enum::MoreFields::Full(454545, 0x87654321, 9988)
23
24 // gdbg-command:print empty_gdb->discr
25 // gdbr-command:print empty_gdb.discr
26 // gdb-check:$4 = (isize *) 0x0
27
28 // gdb-command:print droid
29 // gdbg-check:$5 = {RUST$ENCODED$ENUM$2$Void = {id = 675675, range = 10000001, internals = 0x43218765}}
30 // gdbr-check:$5 = option_like_enum::NamedFields::Droid{id: 675675, range: 10000001, internals: 0x43218765}
31
32 // gdbg-command:print void_droid_gdb->internals
33 // gdbr-command:print void_droid_gdb.internals
34 // gdb-check:$6 = (isize *) 0x0
35
36 // gdb-command:print nested_non_zero_yep
37 // gdbg-check:$7 = {RUST$ENCODED$ENUM$1$2$Nope = {__0 = 10.5, __1 = {a = 10, b = 20, c = [...]}}}
38 // gdbr-check:$7 = option_like_enum::NestedNonZero::Yep(10.5, option_like_enum::NestedNonZeroField {a: 10, b: 20, c: 0x[...] "x[...]"})
39
40 // gdb-command:print nested_non_zero_nope
41 // gdbg-check:$8 = {RUST$ENCODED$ENUM$1$2$Nope = {__0 = [...], __1 = {a = [...], b = [...], c = 0x0}}}
42 // gdbr-check:$8 = option_like_enum::NestedNonZero::Nope
43
44 // gdb-command:continue
45
46
47 // === LLDB TESTS ==================================================================================
48
49 // lldb-command:run
50
51 // lldb-command:print some
52 // lldb-check:[...]$0 = Some(&0x12345678)
53
54 // lldb-command:print none
55 // lldb-check:[...]$1 = None
56
57 // lldb-command:print full
58 // lldb-check:[...]$2 = Full(454545, &0x87654321, 9988)
59
60 // lldb-command:print empty
61 // lldb-check:[...]$3 = Empty
62
63 // lldb-command:print droid
64 // lldb-check:[...]$4 = Droid { id: 675675, range: 10000001, internals: &0x43218765 }
65
66 // lldb-command:print void_droid
67 // lldb-check:[...]$5 = Void
68
69 // lldb-command:print some_str
70 // lldb-check:[...]$6 = Some("abc")
71
72 // lldb-command:print none_str
73 // lldb-check:[...]$7 = None
74
75 // lldb-command:print nested_non_zero_yep
76 // lldb-check:[...]$8 = Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] })
77
78 // lldb-command:print nested_non_zero_nope
79 // lldb-check:[...]$9 = Nope
80
81
82 #![feature(omit_gdb_pretty_printer_section)]
83 #![omit_gdb_pretty_printer_section]
84
85 // If a struct has exactly two variants, one of them is empty, and the other one
86 // contains a non-nullable pointer, then this value is used as the discriminator.
87 // The test cases in this file make sure that something readable is generated for
88 // this kind of types.
89 // If the non-empty variant contains a single non-nullable pointer than the whole
90 // item is represented as just a pointer and not wrapped in a struct.
91 // Unfortunately (for these test cases) the content of the non-discriminant fields
92 // in the null-case is not defined. So we just read the discriminator field in
93 // this case (by casting the value to a memory-equivalent struct).
94
95 enum MoreFields<'a> {
96     Full(u32, &'a isize, i16),
97     Empty
98 }
99
100 struct MoreFieldsRepr<'a> {
101     a: u32,
102     discr: &'a isize,
103     b: i16
104 }
105
106 enum NamedFields<'a> {
107     Droid { id: i32, range: i64, internals: &'a isize },
108     Void
109 }
110
111 struct NamedFieldsRepr<'a> {
112     id: i32,
113     range: i64,
114     internals: &'a isize
115 }
116
117 struct NestedNonZeroField<'a> {
118     a: u16,
119     b: u32,
120     c: &'a char,
121 }
122
123 enum NestedNonZero<'a> {
124     Yep(f64, NestedNonZeroField<'a>),
125     Nope
126 }
127
128 fn main() {
129
130     let some_str: Option<&'static str> = Some("abc");
131     let none_str: Option<&'static str> = None;
132
133     let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678_usize) });
134     let none: Option<&u32> = None;
135
136     let full = MoreFields::Full(454545, unsafe { std::mem::transmute(0x87654321_usize) }, 9988);
137
138     let empty = MoreFields::Empty;
139     let empty_gdb: &MoreFieldsRepr = unsafe { std::mem::transmute(&MoreFields::Empty) };
140
141     let droid = NamedFields::Droid {
142         id: 675675,
143         range: 10000001,
144         internals: unsafe { std::mem::transmute(0x43218765_usize) }
145     };
146
147     let void_droid = NamedFields::Void;
148     let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&NamedFields::Void) };
149
150     let x = 'x';
151     let nested_non_zero_yep = NestedNonZero::Yep(
152         10.5,
153         NestedNonZeroField {
154             a: 10,
155             b: 20,
156             c: &x
157         });
158
159     let nested_non_zero_nope = NestedNonZero::Nope;
160
161     zzz(); // #break
162 }
163
164 fn zzz() {()}