]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/mir_refs_correct.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / run-pass / mir_refs_correct.rs
1 // Copyright 2015 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 #![feature(rustc_attrs)]
11 // aux-build:mir_external_refs.rs
12
13
14 extern crate mir_external_refs as ext;
15
16 struct S(u8);
17 #[derive(Debug, PartialEq, Eq)]
18 struct Unit;
19
20 impl S {
21 fn hey() -> u8 { 42 }
22 fn hey2(&self) -> u8 { 44 }
23 }
24
25 trait X {
26 fn hoy(&self) -> u8 { 43 }
27 fn hoy2() -> u8 { 45 }
28 }
29
30 trait F<U> {
31 fn f(self, other: U) -> u64;
32 }
33
34 impl F<u32> for u32 {
35 fn f(self, other: u32) -> u64 { self as u64 + other as u64 }
36 }
37
38 impl F<u64> for u32 {
39 fn f(self, other: u64) -> u64 { self as u64 - other }
40 }
41
42 impl F<u64> for u64 {
43 fn f(self, other: u64) -> u64 { self * other }
44 }
45
46 impl F<u32> for u64 {
47 fn f(self, other: u32) -> u64 { self ^ other as u64 }
48 }
49
50 trait T<I, O> {
51 fn staticmeth(i: I, o: O) -> (I, O) { (i, o) }
52 }
53
54 impl<I, O> T<I, O> for O {}
55
56 impl X for S {}
57
58 enum E {
59 U(u8)
60 }
61
62 #[derive(PartialEq, Debug, Eq)]
63 enum CEnum {
64 A = 0x321,
65 B = 0x123
66 }
67
68 const C: u8 = 84;
69 const C2: [u8; 5] = [42; 5];
70 const C3: [u8; 3] = [42, 41, 40];
71 const C4: fn(u8) -> S = S;
72
73 fn regular() -> u8 {
74 21
75 }
76
77 fn parametric<T>(u: T) -> T {
78 u
79 }
80
81 #[rustc_mir]
82 fn t1() -> fn()->u8 {
83 regular
84 }
85
86 #[rustc_mir]
87 fn t2() -> fn(u8)->E {
88 E::U
89 }
90
91 #[rustc_mir]
92 fn t3() -> fn(u8)->S {
93 S
94 }
95
96 #[rustc_mir]
97 fn t4() -> fn()->u8 {
98 S::hey
99 }
100
101 #[rustc_mir]
102 fn t5() -> fn(&S)-> u8 {
103 <S as X>::hoy
104 }
105
106
107 #[rustc_mir]
108 fn t6() -> fn()->u8{
109 ext::regular_fn
110 }
111
112 #[rustc_mir]
113 fn t7() -> fn(u8)->ext::E {
114 ext::E::U
115 }
116
117 #[rustc_mir]
118 fn t8() -> fn(u8)->ext::S {
119 ext::S
120 }
121
122 #[rustc_mir]
123 fn t9() -> fn()->u8 {
124 ext::S::hey
125 }
126
127 #[rustc_mir]
128 fn t10() -> fn(&ext::S)->u8 {
129 <ext::S as ext::X>::hoy
130 }
131
132 #[rustc_mir]
133 fn t11() -> fn(u8)->u8 {
134 parametric
135 }
136
137 #[rustc_mir]
138 fn t12() -> u8 {
139 C
140 }
141
142 #[rustc_mir]
143 fn t13() -> [u8; 5] {
144 C2
145 }
146
147 #[rustc_mir]
148 fn t13_2() -> [u8; 3] {
149 C3
150 }
151
152 #[rustc_mir]
153 fn t14() -> fn()-> u8 {
154 <S as X>::hoy2
155 }
156
157 #[rustc_mir]
158 fn t15() -> fn(&S)-> u8 {
159 S::hey2
160 }
161
162 #[rustc_mir]
163 fn t16() -> fn(u32, u32)->u64 {
164 F::f
165 }
166
167 #[rustc_mir]
168 fn t17() -> fn(u32, u64)->u64 {
169 F::f
170 }
171
172 #[rustc_mir]
173 fn t18() -> fn(u64, u64)->u64 {
174 F::f
175 }
176
177 #[rustc_mir]
178 fn t19() -> fn(u64, u32)->u64 {
179 F::f
180 }
181
182 #[rustc_mir]
183 fn t20() -> fn(u64, u32)->(u64, u32) {
184 <u32 as T<_, _>>::staticmeth
185 }
186
187 #[rustc_mir]
188 fn t21() -> Unit {
189 Unit
190 }
191
192 #[rustc_mir]
193 fn t22() -> Option<u8> {
194 None
195 }
196
197 #[rustc_mir]
198 fn t23() -> (CEnum, CEnum) {
199 (CEnum::A, CEnum::B)
200 }
201
202 #[rustc_mir]
203 fn t24() -> fn(u8) -> S {
204 C4
205 }
206
207 fn main() {
208 assert_eq!(t1()(), regular());
209
210 assert_eq!(t2() as *mut (), E::U as *mut ());
211 assert_eq!(t3() as *mut (), S as *mut ());
212
213 assert_eq!(t4()(), S::hey());
214 let s = S(42);
215 assert_eq!(t5()(&s), <S as X>::hoy(&s));
216
217
218 assert_eq!(t6()(), ext::regular_fn());
219 assert_eq!(t7() as *mut (), ext::E::U as *mut ());
220 assert_eq!(t8() as *mut (), ext::S as *mut ());
221
222 assert_eq!(t9()(), ext::S::hey());
223 let sext = ext::S(6);
224 assert_eq!(t10()(&sext), <ext::S as ext::X>::hoy(&sext));
225
226 let p = parametric::<u8>;
227 assert_eq!(t11() as *mut (), p as *mut ());
228
229 assert_eq!(t12(), C);
230 assert_eq!(t13(), C2);
231 assert_eq!(t13_2(), C3);
232
233 assert_eq!(t14()(), <S as X>::hoy2());
234 assert_eq!(t15()(&s), S::hey2(&s));
235 assert_eq!(t16()(10u32, 20u32), F::f(10u32, 20u32));
236 assert_eq!(t17()(30u32, 10u64), F::f(30u32, 10u64));
237 assert_eq!(t18()(50u64, 5u64), F::f(50u64, 5u64));
238 assert_eq!(t19()(322u64, 2u32), F::f(322u64, 2u32));
239 assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
240 assert_eq!(t21(), Unit);
241 assert_eq!(t22(), None);
242 assert_eq!(t23(), (CEnum::A, CEnum::B));
243 assert_eq!(t24(), C4);
244 }