1 // ignore-tidy-linelength
3 // ignore-gdb // Test temporarily ignored due to debuginfo tests being disabled, see PR 47155
10 // gdb-command:whatis simple_struct
11 // gdbg-check:type = struct Struct1
12 // gdbr-check:type = type_names::Struct1
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>
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>
22 // gdb-command:whatis mod_struct
23 // gdbg-check:type = struct Struct2
24 // gdbr-check:type = type_names::mod1::Struct2
28 // gdb-command:whatis simple_enum_1
29 // gdbg-check:type = union Enum1
30 // gdbr-check:type = type_names::Enum1
32 // gdb-command:whatis simple_enum_2
33 // gdbg-check:type = union Enum1
34 // gdbr-check:type = type_names::Enum1
36 // gdb-command:whatis simple_enum_3
37 // gdbg-check:type = union Enum2
38 // gdbr-check:type = type_names::mod1::Enum2
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>
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>
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>)
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)
60 // gdb-command:whatis box1
61 // gdbg-check:type = struct (alloc::boxed::Box<f32>, i32)
62 // gdbr-check:type = (alloc::boxed::Box<f32>, i32)
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)
70 // gdb-command:whatis ref1
71 // gdbg-check:type = struct (&type_names::Struct1, i32)
72 // gdbr-check:type = (&type_names::Struct1, i32)
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)
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)
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)
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)
92 // gdb-command:whatis mut_ptr2
93 // gdbg-check:type = struct (*mut isize, isize)
94 // gdbr-check:type = (*mut isize, isize)
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)
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)
104 // gdb-command:whatis const_ptr2
105 // gdbg-check:type = struct (*const isize, isize)
106 // gdbr-check:type = (*const isize, isize)
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)
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)
118 // gdb-command:whatis fixed_size_vec2
119 // gdbg-check:type = struct ([usize; 3], i16)
120 // gdbr-check:type = ([usize; 3], i16)
122 // gdb-command:whatis slice1
123 // gdbg-check:type = struct &[usize]
124 // gdbr-check:type = &[usize]
126 // gdb-command:whatis slice2
127 // gdbg-check:type = struct &[type_names::mod1::Enum2]
128 // gdbr-check:type = &[type_names::mod1::Enum2]
132 // gdb-command:whatis box_trait
133 // gdbg-check:type = struct Box<Trait1>
134 // gdbr-check:type = type_names::Box<Trait1>
136 // gdb-command:whatis ref_trait
137 // gdbg-check:type = struct &Trait1
138 // gdbr-check:type = type_names::&Trait1
140 // gdb-command:whatis mut_ref_trait
141 // gdbg-check:type = struct &mut Trait1
142 // gdbr-check:type = type_names::&mut Trait1
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>>
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>
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>>
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)
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)
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)
170 // gdb-command:whatis extern_stdcall_fn
171 // gdbg-check:type = struct (extern "stdcall" fn(), usize)
172 // gdbr-check:type = (extern "stdcall" fn(), usize)
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)
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)
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)
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)
190 // gdb-command:whatis generic_function_int
191 // gdbg-check:type = struct (fn(isize) -> isize, usize)
192 // gdbr-check:type = (fn(isize) -> isize, usize)
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)
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)
204 // gdb-command:whatis closure1
205 // gdbg-check:type = struct (closure, usize)
206 // gdbr-check:type = (closure, usize)
208 // gdb-command:whatis closure2
209 // gdbg-check:type = struct (closure, usize)
210 // gdbr-check:type = (closure, usize)
212 #![feature(box_syntax)]
213 #![allow(unused_variables)]
214 #![feature(omit_gdb_pretty_printer_section)]
215 #![omit_gdb_pretty_printer_section]
217 use self::Enum1::{Variant1, Variant2};
218 use std::marker::PhantomData;
222 struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
230 pub use self::Enum2::{Variant1, Variant2};
235 Variant2(super::Struct1),
239 pub use self::Enum3::{Variant1, Variant2};
249 trait Trait1 { fn dummy(&self) { } }
250 trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
252 impl Trait1 for isize {}
253 impl<T1, T2> Trait2<T1, T2> for isize {}
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() {}
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 }
265 fn generic_function<T>(x: T) -> T { x }
267 #[allow(improper_ctypes)]
269 fn printf(_:*const u8, ...) -> isize;
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.
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;
290 let simple_enum_1 = Variant1;
291 let simple_enum_2 = Variant2(0);
292 let simple_enum_3 = mod1::Variant2(Struct1);
294 let generic_enum_1: mod1::mod2::Enum3<mod1::Struct2> = mod1::mod2::Variant1;
295 let generic_enum_2 = mod1::mod2::Variant2(Struct1);
298 let tuple1 = (8u32, Struct1, mod1::mod2::Variant2(mod1::Struct2));
299 let tuple2 = ((Struct1, mod1::mod2::Struct3), mod1::Variant1, 'x');
302 let box1 = (box 1f32, 0i32);
303 let box2 = (box mod1::mod2::Variant2(1f32), 0i32);
306 let ref1 = (&Struct1, 0i32);
307 let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
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);
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);
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);
324 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
325 let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
327 let vec1 = vec![0_usize, 2, 3];
329 let vec2 = vec![mod1::Variant2(Struct1)];
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;
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>;
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>>;
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);
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);
356 let generic_function_int = (generic_function::<isize>, 0_usize);
357 let generic_function_struct3 = (generic_function::<mod1::mod2::Struct3>, 0_usize);
359 let variadic_function = (printf, 0_usize);
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);