]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/type-names.rs
Auto merge of #22517 - brson:relnotes, r=Gankro
[rust.git] / src / test / debuginfo / type-names.rs
1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-linelength
12 // ignore-lldb
13 // ignore-android: FIXME(#10381)
14
15 // compile-flags:-g
16
17 // gdb-command:run
18
19 // STRUCTS
20 // gdb-command:whatis simple_struct
21 // gdb-check:type = struct Struct1
22
23 // gdb-command:whatis generic_struct1
24 // gdb-check:type = struct GenericStruct<type-names::Mod1::Struct2, type-names::Mod1::Mod2::Struct3>
25
26 // gdb-command:whatis generic_struct2
27 // gdb-check:type = struct GenericStruct<type-names::Struct1, extern "fastcall" fn(isize) -> usize>
28
29 // gdb-command:whatis mod_struct
30 // gdb-check:type = struct Struct2
31
32
33 // ENUMS
34 // gdb-command:whatis simple_enum_1
35 // gdb-check:type = union Enum1
36
37 // gdb-command:whatis simple_enum_2
38 // gdb-check:type = union Enum1
39
40 // gdb-command:whatis simple_enum_3
41 // gdb-check:type = union Enum2
42
43 // gdb-command:whatis generic_enum_1
44 // gdb-check:type = union Enum3<type-names::Mod1::Struct2>
45
46 // gdb-command:whatis generic_enum_2
47 // gdb-check:type = union Enum3<type-names::Struct1>
48
49
50 // TUPLES
51 // gdb-command:whatis tuple1
52 // gdb-check:type = struct (u32, type-names::Struct1, type-names::Mod1::Mod2::Enum3<type-names::Mod1::Struct2>)
53
54 // gdb-command:whatis tuple2
55 // gdb-check:type = struct ((type-names::Struct1, type-names::Mod1::Mod2::Struct3), type-names::Mod1::Enum2, char)
56
57
58 // BOX
59 // gdb-command:whatis box1
60 // gdb-check:type = struct (Box<f32>, i32)
61
62 // gdb-command:whatis box2
63 // gdb-check:type = struct (Box<type-names::Mod1::Mod2::Enum3<f32>>, i32)
64
65
66 // REFERENCES
67 // gdb-command:whatis ref1
68 // gdb-check:type = struct (&type-names::Struct1, i32)
69
70 // gdb-command:whatis ref2
71 // gdb-check:type = struct (&type-names::GenericStruct<char, type-names::Struct1>, i32)
72
73 // gdb-command:whatis mut_ref1
74 // gdb-check:type = struct (&mut type-names::Struct1, i32)
75
76 // gdb-command:whatis mut_ref2
77 // gdb-check:type = struct (&mut type-names::GenericStruct<type-names::Mod1::Enum2, f64>, i32)
78
79
80 // RAW POINTERS
81 // gdb-command:whatis mut_ptr1
82 // gdb-check:type = struct (*mut type-names::Struct1, isize)
83
84 // gdb-command:whatis mut_ptr2
85 // gdb-check:type = struct (*mut isize, isize)
86
87 // gdb-command:whatis mut_ptr3
88 // gdb-check:type = struct (*mut type-names::Mod1::Mod2::Enum3<type-names::Struct1>, isize)
89
90 // gdb-command:whatis const_ptr1
91 // gdb-check:type = struct (*const type-names::Struct1, isize)
92
93 // gdb-command:whatis const_ptr2
94 // gdb-check:type = struct (*const isize, isize)
95
96 // gdb-command:whatis const_ptr3
97 // gdb-check:type = struct (*const type-names::Mod1::Mod2::Enum3<type-names::Struct1>, isize)
98
99
100 // VECTORS
101 // gdb-command:whatis fixed_size_vec1
102 // gdb-check:type = struct ([type-names::Struct1; 3], i16)
103
104 // gdb-command:whatis fixed_size_vec2
105 // gdb-check:type = struct ([usize; 3], i16)
106
107 // gdb-command:whatis slice1
108 // gdb-check:type = struct &[usize]
109
110 // gdb-command:whatis slice2
111 // gdb-check:type = struct &[type-names::Mod1::Enum2]
112
113
114 // TRAITS
115 // gdb-command:whatis box_trait
116 // gdb-check:type = struct Box<Trait1>
117
118 // gdb-command:whatis ref_trait
119 // gdb-check:type = struct &Trait1
120
121 // gdb-command:whatis mut_ref_trait
122 // gdb-check:type = struct &mut Trait1
123
124 // gdb-command:whatis generic_box_trait
125 // gdb-check:type = struct Box<Trait2<i32, type-names::Mod1::Struct2>>
126
127 // gdb-command:whatis generic_ref_trait
128 // gdb-check:type = struct &Trait2<type-names::Struct1, type-names::Struct1>
129
130 // gdb-command:whatis generic_mut_ref_trait
131 // gdb-check:type = struct &mut Trait2<type-names::Mod1::Mod2::Struct3, type-names::GenericStruct<usize, isize>>
132
133
134 // BARE FUNCTIONS
135 // gdb-command:whatis rust_fn
136 // gdb-check:type = struct (fn(core::option::Option<isize>, core::option::Option<&type-names::Mod1::Struct2>), usize)
137
138 // gdb-command:whatis extern_c_fn
139 // gdb-check:type = struct (extern "C" fn(isize), usize)
140
141 // gdb-command:whatis unsafe_fn
142 // gdb-check:type = struct (unsafe fn(core::result::Result<char, f64>), usize)
143
144 // gdb-command:whatis extern_stdcall_fn
145 // gdb-check:type = struct (extern "stdcall" fn(), usize)
146
147 // gdb-command:whatis rust_fn_with_return_value
148 // gdb-check:type = struct (fn(f64) -> usize, usize)
149
150 // gdb-command:whatis extern_c_fn_with_return_value
151 // gdb-check:type = struct (extern "C" fn() -> type-names::Struct1, usize)
152
153 // gdb-command:whatis unsafe_fn_with_return_value
154 // gdb-check:type = struct (unsafe fn(type-names::GenericStruct<u16, u8>) -> type-names::Mod1::Struct2, usize)
155
156 // gdb-command:whatis extern_stdcall_fn_with_return_value
157 // gdb-check:type = struct (extern "stdcall" fn(Box<isize>) -> usize, usize)
158
159 // gdb-command:whatis generic_function_int
160 // gdb-check:type = struct (fn(isize) -> isize, usize)
161
162 // gdb-command:whatis generic_function_struct3
163 // gdb-check:type = struct (fn(type-names::Mod1::Mod2::Struct3) -> type-names::Mod1::Mod2::Struct3, usize)
164
165 // gdb-command:whatis variadic_function
166 // gdb-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
167
168
169 // CLOSURES
170 // gdb-command:whatis closure1
171 // gdb-check:type = struct (closure, usize)
172
173 // gdb-command:whatis closure2
174 // gdb-check:type = struct (closure, usize)
175
176 #![feature(box_syntax)]
177 #![omit_gdb_pretty_printer_section]
178
179 use self::Enum1::{Variant1_1, Variant1_2};
180 use std::ptr;
181
182 struct Struct1;
183 struct GenericStruct<T1, T2>;
184
185 enum Enum1 {
186     Variant1_1,
187     Variant1_2(isize)
188 }
189
190 mod Mod1 {
191     pub use self::Enum2::{Variant2_1, Variant2_2};
192     pub struct Struct2;
193
194     pub enum Enum2 {
195         Variant2_1,
196         Variant2_2(super::Struct1)
197     }
198
199     pub mod Mod2 {
200         pub use self::Enum3::{Variant3_1, Variant3_2};
201         pub struct Struct3;
202
203         pub enum Enum3<T> {
204             Variant3_1,
205             Variant3_2(T),
206         }
207     }
208 }
209
210 trait Trait1 { }
211 trait Trait2<T1, T2> { }
212
213 impl Trait1 for isize {}
214 impl<T1, T2> Trait2<T1, T2> for isize {}
215
216 fn rust_fn(_: Option<isize>, _: Option<&Mod1::Struct2>) {}
217 extern "C" fn extern_c_fn(_: isize) {}
218 unsafe fn unsafe_fn(_: Result<char, f64>) {}
219 extern "stdcall" fn extern_stdcall_fn() {}
220
221 fn rust_fn_with_return_value(_: f64) -> usize { 4 }
222 extern "C" fn extern_c_fn_with_return_value() -> Struct1 { Struct1 }
223 unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> Mod1::Struct2 { Mod1::Struct2 }
224 extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<isize>) -> usize { 0 }
225
226 fn generic_function<T>(x: T) -> T { x }
227
228 extern {
229     fn printf(_:*const u8, ...) -> isize;
230 }
231
232 // In many of the cases below, the type that is actually under test is wrapped
233 // in a tuple, e.g. Box<T>, references, raw pointers, fixed-size vectors, ...
234 // This is because GDB will not print the type name from DWARF debuginfo for
235 // some kinds of types (pointers, arrays, functions, ...)
236 // Since tuples are structs as far as GDB is concerned, their name will be
237 // printed correctly, so the tests below just construct a tuple type that will
238 // then *contain* the type name that we want to see.
239 fn main() {
240
241     // Structs
242     let simple_struct = Struct1;
243     let generic_struct1: GenericStruct<Mod1::Struct2, Mod1::Mod2::Struct3> = GenericStruct;
244     let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> = GenericStruct;
245     let mod_struct = Mod1::Struct2;
246
247     // Enums
248     let simple_enum_1 = Variant1_1;
249     let simple_enum_2 = Variant1_2(0);
250     let simple_enum_3 = Mod1::Variant2_2(Struct1);
251
252     let generic_enum_1: Mod1::Mod2::Enum3<Mod1::Struct2> = Mod1::Mod2::Variant3_1;
253     let generic_enum_2 = Mod1::Mod2::Variant3_2(Struct1);
254
255     // Tuples
256     let tuple1 = (8u32, Struct1, Mod1::Mod2::Variant3_2(Mod1::Struct2));
257     let tuple2 = ((Struct1, Mod1::Mod2::Struct3), Mod1::Variant2_1, 'x');
258
259     // Box
260     let box1 = (box 1f32, 0i32);
261     let box2 = (box Mod1::Mod2::Variant3_2(1f32), 0i32);
262
263     // References
264     let ref1 = (&Struct1, 0i32);
265     let ref2 = (&GenericStruct::<char, Struct1>, 0i32);
266
267     let mut mut_struct1 = Struct1;
268     let mut mut_generic_struct = GenericStruct::<Mod1::Enum2, f64>;
269     let mut_ref1 = (&mut mut_struct1, 0i32);
270     let mut_ref2 = (&mut mut_generic_struct, 0i32);
271
272     // Raw Pointers
273     let mut_ptr1: (*mut Struct1, isize) = (ptr::null_mut(), 0);
274     let mut_ptr2: (*mut isize, isize) = (ptr::null_mut(), 0);
275     let mut_ptr3: (*mut Mod1::Mod2::Enum3<Struct1>, isize) = (ptr::null_mut(), 0);
276
277     let const_ptr1: (*const Struct1, isize) = (ptr::null(), 0);
278     let const_ptr2: (*const isize, isize) = (ptr::null(), 0);
279     let const_ptr3: (*const Mod1::Mod2::Enum3<Struct1>, isize) = (ptr::null(), 0);
280
281     // Vectors
282     let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
283     let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
284
285     let vec1 = vec![0_usize, 2, 3];
286     let slice1 = &*vec1;
287     let vec2 = vec![Mod1::Variant2_2(Struct1)];
288     let slice2 = &*vec2;
289
290     // Trait Objects
291     let box_trait = (box 0) as Box<Trait1>;
292     let ref_trait = &0 as &Trait1;
293     let mut mut_int1 = 0;
294     let mut_ref_trait = (&mut mut_int1) as &mut Trait1;
295
296     let generic_box_trait = (box 0) as Box<Trait2<i32, Mod1::Struct2>>;
297     let generic_ref_trait  = (&0) as &Trait2<Struct1, Struct1>;
298
299     let mut generic_mut_ref_trait_impl = 0;
300     let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as
301         &mut Trait2<Mod1::Mod2::Struct3, GenericStruct<usize, isize>>;
302
303     // Bare Functions
304     let rust_fn = (rust_fn, 0_usize);
305     let extern_c_fn = (extern_c_fn, 0_usize);
306     let unsafe_fn = (unsafe_fn, 0_usize);
307     let extern_stdcall_fn = (extern_stdcall_fn, 0_usize);
308
309     let rust_fn_with_return_value = (rust_fn_with_return_value, 0_usize);
310     let extern_c_fn_with_return_value = (extern_c_fn_with_return_value, 0_usize);
311     let unsafe_fn_with_return_value = (unsafe_fn_with_return_value, 0_usize);
312     let extern_stdcall_fn_with_return_value = (extern_stdcall_fn_with_return_value, 0_usize);
313
314     let generic_function_int = (generic_function::<isize>, 0_usize);
315     let generic_function_struct3 = (generic_function::<Mod1::Mod2::Struct3>, 0_usize);
316
317     let variadic_function = (printf, 0_usize);
318
319     // Closures
320     // I (mw) am a bit unclear about the current state of closures, their
321     // various forms (boxed, unboxed, proc, capture-by-ref, by-val, once) and
322     // how that maps to rustc's internal representation of these forms.
323     // Once closures have reached their 1.0 form, the tests below should
324     // probably be expanded.
325     let closure1 = (|x:isize| {}, 0_usize);
326     let closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0_usize);
327
328     zzz(); // #break
329 }
330
331 #[inline(never)]
332 fn zzz() { () }