1 // Copyright (C) 2016-2020 Free Software Foundation, Inc.
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #![allow(unused_variables)]
18 #![allow(unused_assignments)]
26 struct ByeBob(i32, u64);
34 enum MoreComplicated {
38 Four{this: bool, is: u8, a: char, struct_: u64, variant: u32},
41 // tests the nonzero optimization, but fields are reversed
42 enum NonZeroOptimized {
47 fn diff2(x: i32, y: i32) -> i32 {
51 // Empty function, should not have "void"
52 // or "()" in its return type
59 // This triggers the non-zero optimization that yields a different
60 // enum representation in the debug info.
73 enum ParametrizedEnum<T> {
78 struct ParametrizedStruct<T> {
79 next: ParametrizedEnum<Box<ParametrizedStruct<T>>>,
83 struct StringAtOffset {
84 pub field1: &'static str,
86 pub field3: &'static str,
89 // A simple structure whose layout won't be changed by the compiler,
90 // so that ptype/o testing will work on any platform.
99 struct EnumWithNonzeroOffset {
106 let b : [i32; 0] = [];
111 let e = MoreComplicated::Two(73);
112 let e2 = MoreComplicated::Four {this: true, is: 8, a: 'm',
113 struct_: 100, variant: 10};
119 let fslice = &f[3..];
121 let i = ["whatever"; 8];
126 let k = SpaceSaver::Nothing;
127 let l = SpaceSaver::Thebox(9, Box::new(1729));
129 let v = Something::Three;
133 let y = HiBob {field1: 7, field2: 8};
134 let z = ByeBob(7, 8);
139 let univariant = Univariant::Foo {a : 1};
140 let univariant_anon = UnivariantAnon::Foo(1);
142 let slice = &w[2..3];
143 let fromslice = slice[0];
144 let slice2 = &slice[0..1];
147 let all2 = &slice[..];
150 let from2 = &slice[1..];
153 let to2 = &slice[..1];
155 let st = StringAtOffset { field1: "hello", field2: 1, field3: "world" };
157 // tests for enum optimizations
159 let str_some = Some("hi".to_string());
160 let str_none = None::<String>;
161 let box_some = Some(Box::new(1u8));
162 let box_none = None::<Box<u8>>;
163 let int_some = Some(1u8);
164 let int_none = None::<u8>;
165 let custom_some = NonZeroOptimized::Value("hi".into());
166 let custom_none = NonZeroOptimized::Empty;
168 let parametrized = ParametrizedStruct {
169 next: ParametrizedEnum::Val {
170 val: Box::new(ParametrizedStruct {
171 next: ParametrizedEnum::Empty,
178 let simplelayout = SimpleLayout { f1: 8, f2: 9 };
180 let empty_enum_value: EmptyEnum;
182 let nonzero_offset = EnumWithNonzeroOffset { a: Some(1), b: None };
184 println!("{}, {}", x.0, x.1); // set breakpoint here
185 println!("{}", diff2(92, 45));