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