]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/option-like-enum.rs
Update debuginfo tests.
[rust.git] / src / test / debuginfo / option-like-enum.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-android: FIXME(#10381)
12
13 // compile-flags:-g
14 // gdb-command:rbreak zzz
15 // gdb-command:run
16 // gdb-command:finish
17
18 // gdb-command:print some
19 // gdb-check:$1 = (u32 *) 0x12345678
20
21 // gdb-command:print none
22 // gdb-check:$2 = (u32 *) 0x0
23
24 // gdb-command:print full
25 // gdb-check:$3 = {454545, 0x87654321, 9988}
26
27 // gdb-command:print empty->discr
28 // gdb-check:$4 = (int *) 0x0
29
30 // gdb-command:print droid
31 // gdb-check:$5 = {id = 675675, range = 10000001, internals = 0x43218765}
32
33 // gdb-command:print void_droid->internals
34 // gdb-check:$6 = (int *) 0x0
35
36 // gdb-command:continue
37
38 #![feature(struct_variant)]
39
40 // If a struct has exactly two variants, one of them is empty, and the other one
41 // contains a non-nullable pointer, then this value is used as the discriminator.
42 // The test cases in this file make sure that something readable is generated for
43 // this kind of types.
44 // If the non-empty variant contains a single non-nullable pointer than the whole
45 // item is represented as just a pointer and not wrapped in a struct.
46 // Unfortunately (for these test cases) the content of the non-discriminant fields
47 // in the null-case is not defined. So we just read the discriminator field in
48 // this case (by casting the value to a memory-equivalent struct).
49
50 enum MoreFields<'a> {
51     Full(u32, &'a int, i16),
52     Empty
53 }
54
55 struct MoreFieldsRepr<'a> {
56     a: u32,
57     discr: &'a int,
58     b: i16
59 }
60
61 enum NamedFields<'a> {
62     Droid { id: i32, range: i64, internals: &'a int },
63     Void
64 }
65
66 struct NamedFieldsRepr<'a> {
67     id: i32,
68     range: i64,
69     internals: &'a int
70 }
71
72 fn main() {
73
74     let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678) });
75     let none: Option<&u32> = None;
76
77     let full = Full(454545, unsafe { std::mem::transmute(0x87654321) }, 9988);
78
79     let int_val = 0;
80     let empty: &MoreFieldsRepr = unsafe { std::mem::transmute(&Empty) };
81
82     let droid = Droid {
83         id: 675675,
84         range: 10000001,
85         internals: unsafe { std::mem::transmute(0x43218765) }
86     };
87
88     let void_droid: &NamedFieldsRepr = unsafe { std::mem::transmute(&Void) };
89
90     zzz();
91 }
92
93 fn zzz() {()}