]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/recursive-struct.rs
rustdoc: Fix handling of compile errors when running `rustdoc --test`
[rust.git] / src / test / debuginfo / recursive-struct.rs
1 // ignore-lldb
2
3 // Require LLVM with DW_TAG_variant_part and a gdb that can read it.
4 // min-system-llvm-version: 8.0
5 // min-gdb-version: 8.2
6
7 // compile-flags:-g
8
9 // gdb-command:run
10
11 // gdb-command:print stack_unique.value
12 // gdb-check:$1 = 0
13 // gdbr-command:print stack_unique.next.val.value
14 // gdb-check:$2 = 1
15
16 // gdbr-command:print unique_unique.value
17 // gdb-check:$3 = 2
18 // gdbr-command:print unique_unique.next.val.value
19 // gdb-check:$4 = 3
20
21 // gdb-command:print vec_unique[0].value
22 // gdb-check:$5 = 6.5
23 // gdbr-command:print vec_unique[0].next.val.value
24 // gdb-check:$6 = 7.5
25
26 // gdbr-command:print borrowed_unique.value
27 // gdb-check:$7 = 8.5
28 // gdbr-command:print borrowed_unique.next.val.value
29 // gdb-check:$8 = 9.5
30
31 // LONG CYCLE
32 // gdb-command:print long_cycle1.value
33 // gdb-check:$9 = 20
34 // gdbr-command:print long_cycle1.next.value
35 // gdb-check:$10 = 21
36 // gdbr-command:print long_cycle1.next.next.value
37 // gdb-check:$11 = 22
38 // gdbr-command:print long_cycle1.next.next.next.value
39 // gdb-check:$12 = 23
40
41 // gdb-command:print long_cycle2.value
42 // gdb-check:$13 = 24
43 // gdbr-command:print long_cycle2.next.value
44 // gdb-check:$14 = 25
45 // gdbr-command:print long_cycle2.next.next.value
46 // gdb-check:$15 = 26
47
48 // gdb-command:print long_cycle3.value
49 // gdb-check:$16 = 27
50 // gdbr-command:print long_cycle3.next.value
51 // gdb-check:$17 = 28
52
53 // gdb-command:print long_cycle4.value
54 // gdb-check:$18 = 29.5
55
56 // gdbr-command:print long_cycle_w_anonymous_types.value
57 // gdb-check:$19 = 30
58
59 // gdbr-command:print long_cycle_w_anonymous_types.next.val.value
60 // gdb-check:$20 = 31
61
62 // gdb-command:continue
63
64 #![allow(unused_variables)]
65 #![feature(box_syntax)]
66 #![feature(omit_gdb_pretty_printer_section)]
67 #![omit_gdb_pretty_printer_section]
68
69 use self::Opt::{Empty, Val};
70
71 enum Opt<T> {
72     Empty,
73     Val { val: T }
74 }
75
76 struct UniqueNode<T> {
77     next: Opt<Box<UniqueNode<T>>>,
78     value: T
79 }
80
81 struct LongCycle1<T> {
82     next: Box<LongCycle2<T>>,
83     value: T,
84 }
85
86 struct LongCycle2<T> {
87     next: Box<LongCycle3<T>>,
88     value: T,
89 }
90
91 struct LongCycle3<T> {
92     next: Box<LongCycle4<T>>,
93     value: T,
94 }
95
96 struct LongCycle4<T> {
97     next: Option<Box<LongCycle1<T>>>,
98     value: T,
99 }
100
101 struct LongCycleWithAnonymousTypes {
102     next: Opt<Box<Box<Box<Box<Box<LongCycleWithAnonymousTypes>>>>>>,
103     value: usize,
104 }
105
106 // This test case makes sure that recursive structs are properly described. The Node structs are
107 // generic so that we can have a new type (that newly needs to be described) for the different
108 // cases. The potential problem with recursive types is that the DI generation algorithm gets
109 // trapped in an endless loop. To make sure, we actually test this in the different cases, we have
110 // to operate on a new type each time, otherwise we would just hit the DI cache for all but the
111 // first case.
112
113 // The different cases below (stack_*, unique_*, box_*, etc) are set up so that the type description
114 // algorithm will enter the type reference cycle that is created by a recursive definition from a
115 // different context each time.
116
117 // The "long cycle" cases are constructed to span a longer, indirect recursion cycle between types.
118 // The different locals will cause the DI algorithm to enter the type reference cycle at different
119 // points.
120
121 fn main() {
122     let stack_unique: UniqueNode<u16> = UniqueNode {
123         next: Val {
124             val: box UniqueNode {
125                 next: Empty,
126                 value: 1,
127             }
128         },
129         value: 0,
130     };
131
132     let unique_unique: Box<UniqueNode<u32>> = box UniqueNode {
133         next: Val {
134             val: box UniqueNode {
135                 next: Empty,
136                 value: 3,
137             }
138         },
139         value: 2,
140     };
141
142     let vec_unique: [UniqueNode<f32>; 1] = [UniqueNode {
143         next: Val {
144             val: box UniqueNode {
145                 next: Empty,
146                 value: 7.5,
147             }
148         },
149         value: 6.5,
150     }];
151
152     let borrowed_unique: &UniqueNode<f64> = &UniqueNode {
153         next: Val {
154             val: box UniqueNode {
155                 next: Empty,
156                 value: 9.5,
157             }
158         },
159         value: 8.5,
160     };
161
162     // LONG CYCLE
163     let long_cycle1: LongCycle1<u16> = LongCycle1 {
164         next: box LongCycle2 {
165             next: box LongCycle3 {
166                 next: box LongCycle4 {
167                     next: None,
168                     value: 23,
169                 },
170                 value: 22,
171             },
172             value: 21
173         },
174         value: 20
175     };
176
177     let long_cycle2: LongCycle2<u32> = LongCycle2 {
178         next: box LongCycle3 {
179             next: box LongCycle4 {
180                 next: None,
181                 value: 26,
182             },
183             value: 25,
184         },
185         value: 24
186     };
187
188     let long_cycle3: LongCycle3<u64> = LongCycle3 {
189         next: box LongCycle4 {
190             next: None,
191             value: 28,
192         },
193         value: 27,
194     };
195
196     let long_cycle4: LongCycle4<f32> = LongCycle4 {
197         next: None,
198         value: 29.5,
199     };
200
201     // It's important that LongCycleWithAnonymousTypes is encountered only at the end of the
202     // `box` chain.
203     let long_cycle_w_anonymous_types = box box box box box LongCycleWithAnonymousTypes {
204         next: Val {
205             val: box box box box box LongCycleWithAnonymousTypes {
206                 next: Empty,
207                 value: 31,
208             }
209         },
210         value: 30
211     };
212
213     zzz(); // #break
214 }
215
216 fn zzz() {()}