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.
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.
11 // ignore-tidy-linelength
13 // ignore-android: FIXME(#24958)
20 // gdb-command:whatis simple_struct
21 // gdb-check:type = struct Struct1
23 // gdb-command:whatis generic_struct1
24 // gdb-check:type = struct GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
26 // gdb-command:whatis generic_struct2
27 // gdb-check:type = struct GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
29 // gdb-command:whatis mod_struct
30 // gdb-check:type = struct Struct2
34 // gdb-command:whatis simple_enum_1
35 // gdb-check:type = union Enum1
37 // gdb-command:whatis simple_enum_2
38 // gdb-check:type = union Enum1
40 // gdb-command:whatis simple_enum_3
41 // gdb-check:type = union Enum2
43 // gdb-command:whatis generic_enum_1
44 // gdb-check:type = union Enum3<type_names::mod1::Struct2>
46 // gdb-command:whatis generic_enum_2
47 // gdb-check:type = union Enum3<type_names::Struct1>
51 // gdb-command:whatis tuple1
52 // gdb-check:type = struct (u32, type_names::Struct1, type_names::mod1::mod2::Enum3<type_names::mod1::Struct2>)
54 // gdb-command:whatis tuple2
55 // gdb-check:type = struct ((type_names::Struct1, type_names::mod1::mod2::Struct3), type_names::mod1::Enum2, char)
59 // gdb-command:whatis box1
60 // gdb-check:type = struct (Box<f32>, i32)
62 // gdb-command:whatis box2
63 // gdb-check:type = struct (Box<type_names::mod1::mod2::Enum3<f32>>, i32)
67 // gdb-command:whatis ref1
68 // gdb-check:type = struct (&type_names::Struct1, i32)
70 // gdb-command:whatis ref2
71 // gdb-check:type = struct (&type_names::GenericStruct<char, type_names::Struct1>, i32)
73 // gdb-command:whatis mut_ref1
74 // gdb-check:type = struct (&mut type_names::Struct1, i32)
76 // gdb-command:whatis mut_ref2
77 // gdb-check:type = struct (&mut type_names::GenericStruct<type_names::mod1::Enum2, f64>, i32)
81 // gdb-command:whatis mut_ptr1
82 // gdb-check:type = struct (*mut type_names::Struct1, isize)
84 // gdb-command:whatis mut_ptr2
85 // gdb-check:type = struct (*mut isize, isize)
87 // gdb-command:whatis mut_ptr3
88 // gdb-check:type = struct (*mut type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
90 // gdb-command:whatis const_ptr1
91 // gdb-check:type = struct (*const type_names::Struct1, isize)
93 // gdb-command:whatis const_ptr2
94 // gdb-check:type = struct (*const isize, isize)
96 // gdb-command:whatis const_ptr3
97 // gdb-check:type = struct (*const type_names::mod1::mod2::Enum3<type_names::Struct1>, isize)
101 // gdb-command:whatis fixed_size_vec1
102 // gdb-check:type = struct ([type_names::Struct1; 3], i16)
104 // gdb-command:whatis fixed_size_vec2
105 // gdb-check:type = struct ([usize; 3], i16)
107 // gdb-command:whatis slice1
108 // gdb-check:type = struct &[usize]
110 // gdb-command:whatis slice2
111 // gdb-check:type = struct &[type_names::mod1::Enum2]
115 // gdb-command:whatis box_trait
116 // gdb-check:type = struct Box<Trait1>
118 // gdb-command:whatis ref_trait
119 // gdb-check:type = struct &Trait1
121 // gdb-command:whatis mut_ref_trait
122 // gdb-check:type = struct &mut Trait1
124 // gdb-command:whatis generic_box_trait
125 // gdb-check:type = struct Box<Trait2<i32, type_names::mod1::Struct2>>
127 // gdb-command:whatis generic_ref_trait
128 // gdb-check:type = struct &Trait2<type_names::Struct1, type_names::Struct1>
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>>
135 // gdb-command:whatis rust_fn
136 // gdb-check:type = struct (fn(core::option::Option<isize>, core::option::Option<&type_names::mod1::Struct2>), usize)
138 // gdb-command:whatis extern_c_fn
139 // gdb-check:type = struct (extern "C" fn(isize), usize)
141 // gdb-command:whatis unsafe_fn
142 // gdb-check:type = struct (unsafe fn(core::result::Result<char, f64>), usize)
144 // gdb-command:whatis extern_stdcall_fn
145 // gdb-check:type = struct (extern "stdcall" fn(), usize)
147 // gdb-command:whatis rust_fn_with_return_value
148 // gdb-check:type = struct (fn(f64) -> usize, usize)
150 // gdb-command:whatis extern_c_fn_with_return_value
151 // gdb-check:type = struct (extern "C" fn() -> type_names::Struct1, usize)
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)
156 // gdb-command:whatis extern_stdcall_fn_with_return_value
157 // gdb-check:type = struct (extern "stdcall" fn(Box<isize>) -> usize, usize)
159 // gdb-command:whatis generic_function_int
160 // gdb-check:type = struct (fn(isize) -> isize, usize)
162 // gdb-command:whatis generic_function_struct3
163 // gdb-check:type = struct (fn(type_names::mod1::mod2::Struct3) -> type_names::mod1::mod2::Struct3, usize)
165 // gdb-command:whatis variadic_function
166 // gdb-check:type = struct (unsafe extern "C" fn(*const u8, ...) -> isize, usize)
170 // gdb-command:whatis closure1
171 // gdb-check:type = struct (closure, usize)
173 // gdb-command:whatis closure2
174 // gdb-check:type = struct (closure, usize)
176 #![feature(box_syntax)]
177 #![allow(unused_variables)]
178 #![feature(omit_gdb_pretty_printer_section)]
179 #![omit_gdb_pretty_printer_section]
181 use self::Enum1::{Variant1, Variant2};
182 use std::marker::PhantomData;
186 struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
194 pub use self::Enum2::{Variant1, Variant2};
199 Variant2(super::Struct1),
203 pub use self::Enum3::{Variant1, Variant2};
213 trait Trait1 { fn dummy(&self) { } }
214 trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
216 impl Trait1 for isize {}
217 impl<T1, T2> Trait2<T1, T2> for isize {}
219 fn rust_fn(_: Option<isize>, _: Option<&mod1::Struct2>) {}
220 extern "C" fn extern_c_fn(_: isize) {}
221 unsafe fn unsafe_fn(_: Result<char, f64>) {}
222 extern "stdcall" fn extern_stdcall_fn() {}
224 fn rust_fn_with_return_value(_: f64) -> usize { 4 }
225 extern "C" fn extern_c_fn_with_return_value() -> Struct1 { Struct1 }
226 unsafe fn unsafe_fn_with_return_value(_: GenericStruct<u16, u8>) -> mod1::Struct2 { mod1::Struct2 }
227 extern "stdcall" fn extern_stdcall_fn_with_return_value(_: Box<isize>) -> usize { 0 }
229 fn generic_function<T>(x: T) -> T { x }
231 #[allow(improper_ctypes)]
233 fn printf(_:*const u8, ...) -> isize;
236 // In many of the cases below, the type that is actually under test is wrapped
237 // in a tuple, e.g. Box<T>, references, raw pointers, fixed-size vectors, ...
238 // This is because GDB will not print the type name from DWARF debuginfo for
239 // some kinds of types (pointers, arrays, functions, ...)
240 // Since tuples are structs as far as GDB is concerned, their name will be
241 // printed correctly, so the tests below just construct a tuple type that will
242 // then *contain* the type name that we want to see.
246 let simple_struct = Struct1;
247 let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
248 GenericStruct(PhantomData);
249 let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> =
250 GenericStruct(PhantomData);
251 let mod_struct = mod1::Struct2;
254 let simple_enum_1 = Variant1;
255 let simple_enum_2 = Variant2(0);
256 let simple_enum_3 = mod1::Variant2(Struct1);
258 let generic_enum_1: mod1::mod2::Enum3<mod1::Struct2> = mod1::mod2::Variant1;
259 let generic_enum_2 = mod1::mod2::Variant2(Struct1);
262 let tuple1 = (8u32, Struct1, mod1::mod2::Variant2(mod1::Struct2));
263 let tuple2 = ((Struct1, mod1::mod2::Struct3), mod1::Variant1, 'x');
266 let box1 = (box 1f32, 0i32);
267 let box2 = (box mod1::mod2::Variant2(1f32), 0i32);
270 let ref1 = (&Struct1, 0i32);
271 let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
273 let mut mut_struct1 = Struct1;
274 let mut mut_generic_struct = GenericStruct::<mod1::Enum2, f64>(PhantomData);
275 let mut_ref1 = (&mut mut_struct1, 0i32);
276 let mut_ref2 = (&mut mut_generic_struct, 0i32);
279 let mut_ptr1: (*mut Struct1, isize) = (ptr::null_mut(), 0);
280 let mut_ptr2: (*mut isize, isize) = (ptr::null_mut(), 0);
281 let mut_ptr3: (*mut mod1::mod2::Enum3<Struct1>, isize) = (ptr::null_mut(), 0);
283 let const_ptr1: (*const Struct1, isize) = (ptr::null(), 0);
284 let const_ptr2: (*const isize, isize) = (ptr::null(), 0);
285 let const_ptr3: (*const mod1::mod2::Enum3<Struct1>, isize) = (ptr::null(), 0);
288 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
289 let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
291 let vec1 = vec![0_usize, 2, 3];
293 let vec2 = vec![mod1::Variant2(Struct1)];
297 let box_trait = (box 0_isize) as Box<Trait1>;
298 let ref_trait = &0_isize as &Trait1;
299 let mut mut_int1 = 0_isize;
300 let mut_ref_trait = (&mut mut_int1) as &mut Trait1;
302 let generic_box_trait = (box 0_isize) as Box<Trait2<i32, mod1::Struct2>>;
303 let generic_ref_trait = (&0_isize) as &Trait2<Struct1, Struct1>;
305 let mut generic_mut_ref_trait_impl = 0_isize;
306 let generic_mut_ref_trait = (&mut generic_mut_ref_trait_impl) as
307 &mut Trait2<mod1::mod2::Struct3, GenericStruct<usize, isize>>;
310 let rust_fn = (rust_fn, 0_usize);
311 let extern_c_fn = (extern_c_fn, 0_usize);
312 let unsafe_fn = (unsafe_fn, 0_usize);
313 let extern_stdcall_fn = (extern_stdcall_fn, 0_usize);
315 let rust_fn_with_return_value = (rust_fn_with_return_value, 0_usize);
316 let extern_c_fn_with_return_value = (extern_c_fn_with_return_value, 0_usize);
317 let unsafe_fn_with_return_value = (unsafe_fn_with_return_value, 0_usize);
318 let extern_stdcall_fn_with_return_value = (extern_stdcall_fn_with_return_value, 0_usize);
320 let generic_function_int = (generic_function::<isize>, 0_usize);
321 let generic_function_struct3 = (generic_function::<mod1::mod2::Struct3>, 0_usize);
323 let variadic_function = (printf, 0_usize);
326 // I (mw) am a bit unclear about the current state of closures, their
327 // various forms (boxed, unboxed, proc, capture-by-ref, by-val, once) and
328 // how that maps to rustc's internal representation of these forms.
329 // Once closures have reached their 1.0 form, the tests below should
330 // probably be expanded.
331 let closure1 = (|x:isize| {}, 0_usize);
332 let closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0_usize);