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-android: FIXME(#10381)
14 // gdb-command:rbreak zzz
18 // gdb-command:print some
19 // gdb-check:$1 = (u32 *) 0x12345678
21 // gdb-command:print none
22 // gdb-check:$2 = (u32 *) 0x0
24 // gdb-command:print full
25 // gdb-check:$3 = {454545, 0x87654321, 9988}
27 // gdb-command:print empty->discr
28 // gdb-check:$4 = (int *) 0x0
30 // gdb-command:print droid
31 // gdb-check:$5 = {id = 675675, range = 10000001, internals = 0x43218765}
33 // gdb-command:print void_droid->internals
34 // gdb-check:$6 = (int *) 0x0
36 // gdb-command:continue
38 #![feature(struct_variant)]
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).
51 Full(u32, &'a int, i16),
55 struct MoreFieldsRepr<'a> {
61 enum NamedFields<'a> {
62 Droid { id: i32, range: i64, internals: &'a int },
66 struct NamedFieldsRepr<'a> {
74 let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678) });
75 let none: Option<&u32> = None;
77 let full = Full(454545, unsafe { std::mem::transmute(0x87654321) }, 9988);
80 let empty: &MoreFieldsRepr = unsafe { std::mem::transmute(&Empty) };
85 internals: unsafe { std::mem::transmute(0x43218765) }
88 let void_droid: &NamedFieldsRepr = unsafe { std::mem::transmute(&Void) };