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(#10381)
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 #![omit_gdb_pretty_printer_section]
179 use self::Enum1::{Variant1_1, Variant1_2};
183 struct GenericStruct<T1, T2>;
191 pub use self::Enum2::{Variant2_1, Variant2_2};
196 Variant2_2(super::Struct1)
200 pub use self::Enum3::{Variant3_1, Variant3_2};
211 trait Trait2<T1, T2> { }
213 impl Trait1 for isize {}
214 impl<T1, T2> Trait2<T1, T2> for isize {}
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() {}
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 }
226 fn generic_function<T>(x: T) -> T { x }
229 fn printf(_:*const u8, ...) -> isize;
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.
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;
248 let simple_enum_1 = Variant1_1;
249 let simple_enum_2 = Variant1_2(0);
250 let simple_enum_3 = Mod1::Variant2_2(Struct1);
252 let generic_enum_1: Mod1::Mod2::Enum3<Mod1::Struct2> = Mod1::Mod2::Variant3_1;
253 let generic_enum_2 = Mod1::Mod2::Variant3_2(Struct1);
256 let tuple1 = (8u32, Struct1, Mod1::Mod2::Variant3_2(Mod1::Struct2));
257 let tuple2 = ((Struct1, Mod1::Mod2::Struct3), Mod1::Variant2_1, 'x');
260 let box1 = (box 1f32, 0i32);
261 let box2 = (box Mod1::Mod2::Variant3_2(1f32), 0i32);
264 let ref1 = (&Struct1, 0i32);
265 let ref2 = (&GenericStruct::<char, Struct1>, 0i32);
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);
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);
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);
282 let fixed_size_vec1 = ([Struct1, Struct1, Struct1], 0i16);
283 let fixed_size_vec2 = ([0_usize, 1, 2], 0i16);
285 let vec1 = vec![0_usize, 2, 3];
287 let vec2 = vec![Mod1::Variant2_2(Struct1)];
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;
296 let generic_box_trait = (box 0) as Box<Trait2<i32, Mod1::Struct2>>;
297 let generic_ref_trait = (&0) as &Trait2<Struct1, Struct1>;
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>>;
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);
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);
314 let generic_function_int = (generic_function::<isize>, 0_usize);
315 let generic_function_struct3 = (generic_function::<Mod1::Mod2::Struct3>, 0_usize);
317 let variadic_function = (printf, 0_usize);
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);