Commit | Line | Data |
---|---|---|
e2882c85 | 1 | // Copyright (C) 2016-2018 Free Software Foundation, Inc. |
67218854 TT |
2 | |
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. | |
7 | // | |
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. | |
12 | // | |
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/>. | |
15 | ||
16 | #![allow(dead_code)] | |
17 | #![allow(unused_variables)] | |
18 | #![allow(unused_assignments)] | |
19 | ||
20 | ||
21 | pub struct HiBob { | |
22 | pub field1: i32, | |
23 | field2: u64, | |
24 | } | |
25 | ||
26 | struct ByeBob(i32, u64); | |
27 | ||
28 | enum Something { | |
29 | One, | |
30 | Two, | |
31 | Three | |
32 | } | |
33 | ||
34 | enum MoreComplicated { | |
35 | One, | |
36 | Two(i32), | |
37 | Three(HiBob), | |
38 | Four{this: bool, is: u8, a: char, struct_: u64, variant: u32}, | |
39 | } | |
40 | ||
fccb08f8 MG |
41 | // tests the nonzero optimization, but fields are reversed |
42 | enum NonZeroOptimized { | |
43 | Empty, | |
44 | Value(String), | |
45 | } | |
46 | ||
67218854 TT |
47 | fn diff2(x: i32, y: i32) -> i32 { |
48 | x - y | |
49 | } | |
50 | ||
921d8f54 MG |
51 | // Empty function, should not have "void" |
52 | // or "()" in its return type | |
53 | fn empty() { | |
54 | ||
55 | } | |
56 | ||
67218854 TT |
57 | pub struct Unit; |
58 | ||
59 | // This triggers the non-zero optimization that yields a different | |
60 | // enum representation in the debug info. | |
61 | enum SpaceSaver { | |
62 | Thebox(u8, Box<i32>), | |
63 | Nothing, | |
64 | } | |
65 | ||
51a789c3 MG |
66 | enum Univariant { |
67 | Foo {a: u8} | |
68 | } | |
69 | enum UnivariantAnon { | |
70 | Foo(u8) | |
71 | } | |
72 | ||
73 | enum ParametrizedEnum<T> { | |
74 | Val { val: T }, | |
75 | Empty, | |
76 | } | |
77 | ||
78 | struct ParametrizedStruct<T> { | |
79 | next: ParametrizedEnum<Box<ParametrizedStruct<T>>>, | |
80 | value: T | |
81 | } | |
82 | ||
a037790e TT |
83 | union Union { |
84 | f1: i8, | |
85 | f2: u8, | |
86 | } | |
87 | ||
a33ccfc7 TT |
88 | // A simple structure whose layout won't be changed by the compiler, |
89 | // so that ptype/o testing will work on any platform. | |
90 | struct SimpleLayout { | |
91 | f1: u16, | |
92 | f2: u16 | |
93 | } | |
94 | ||
67218854 TT |
95 | fn main () { |
96 | let a = (); | |
97 | let b : [i32; 0] = []; | |
98 | ||
99 | let mut c = 27; | |
100 | let d = c = 99; | |
101 | ||
102 | let e = MoreComplicated::Two(73); | |
103 | let e2 = MoreComplicated::Four {this: true, is: 8, a: 'm', | |
104 | struct_: 100, variant: 10}; | |
105 | ||
106 | let f = "hi bob"; | |
107 | let g = b"hi bob"; | |
108 | let h = b'9'; | |
109 | ||
45320ffa TT |
110 | let fslice = &f[3..]; |
111 | ||
67218854 TT |
112 | let i = ["whatever"; 8]; |
113 | ||
114 | let j = Unit; | |
12df5c00 | 115 | let j2 = Unit{}; |
67218854 TT |
116 | |
117 | let k = SpaceSaver::Nothing; | |
118 | let l = SpaceSaver::Thebox(9, Box::new(1729)); | |
119 | ||
120 | let v = Something::Three; | |
121 | let w = [1,2,3,4]; | |
42d94011 | 122 | let w_ptr = &w[0]; |
67218854 TT |
123 | let x = (23, 25.5); |
124 | let y = HiBob {field1: 7, field2: 8}; | |
125 | let z = ByeBob(7, 8); | |
126 | ||
92630041 TT |
127 | let field1 = 77; |
128 | let field2 = 88; | |
129 | let y0 = HiBob { field1, field2 }; | |
130 | ||
51a789c3 MG |
131 | let univariant = Univariant::Foo {a : 1}; |
132 | let univariant_anon = UnivariantAnon::Foo(1); | |
133 | ||
67218854 TT |
134 | let slice = &w[2..3]; |
135 | let fromslice = slice[0]; | |
136 | let slice2 = &slice[0..1]; | |
137 | ||
138 | let all1 = &w[..]; | |
139 | let all2 = &slice[..]; | |
140 | ||
141 | let from1 = &w[1..]; | |
142 | let from2 = &slice[1..]; | |
143 | ||
144 | let to1 = &w[..3]; | |
145 | let to2 = &slice[..1]; | |
146 | ||
fccb08f8 MG |
147 | // tests for enum optimizations |
148 | ||
149 | let str_some = Some("hi".to_string()); | |
150 | let str_none = None::<String>; | |
151 | let box_some = Some(Box::new(1u8)); | |
152 | let box_none = None::<Box<u8>>; | |
153 | let int_some = Some(1u8); | |
154 | let int_none = None::<u8>; | |
155 | let custom_some = NonZeroOptimized::Value("hi".into()); | |
156 | let custom_none = NonZeroOptimized::Empty; | |
157 | ||
51a789c3 MG |
158 | let parametrized = ParametrizedStruct { |
159 | next: ParametrizedEnum::Val { | |
160 | val: Box::new(ParametrizedStruct { | |
161 | next: ParametrizedEnum::Empty, | |
162 | value: 1, | |
163 | }) | |
164 | }, | |
165 | value: 0, | |
166 | }; | |
167 | ||
a037790e | 168 | let u = Union { f2: 255 }; |
a33ccfc7 | 169 | let v = SimpleLayout { f1: 8, f2: 9 }; |
a037790e | 170 | |
67218854 TT |
171 | println!("{}, {}", x.0, x.1); // set breakpoint here |
172 | println!("{}", diff2(92, 45)); | |
921d8f54 | 173 | empty(); |
67218854 | 174 | } |