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