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