]>
Commit | Line | Data |
---|---|---|
9cc50fc6 SL |
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 | ||
9e0c209e | 11 | #[repr(C)] |
9cc50fc6 SL |
12 | enum CEnum { |
13 | Hello = 30, | |
14 | World = 60 | |
15 | } | |
16 | ||
9cc50fc6 SL |
17 | fn test1(c: CEnum) -> i32 { |
18 | let c2 = CEnum::Hello; | |
19 | match (c, c2) { | |
20 | (CEnum::Hello, CEnum::Hello) => 42, | |
21 | (CEnum::World, CEnum::Hello) => 0, | |
22 | _ => 1 | |
23 | } | |
24 | } | |
25 | ||
26 | #[repr(packed)] | |
27 | #[derive(PartialEq, Debug)] | |
28 | struct Pakd { | |
29 | a: u64, | |
30 | b: u32, | |
31 | c: u16, | |
32 | d: u8, | |
33 | e: () | |
34 | } | |
35 | ||
36 | impl Drop for Pakd { | |
37 | fn drop(&mut self) {} | |
38 | } | |
39 | ||
9cc50fc6 SL |
40 | fn test2() -> Pakd { |
41 | Pakd { a: 42, b: 42, c: 42, d: 42, e: () } | |
42 | } | |
43 | ||
44 | #[derive(PartialEq, Debug)] | |
45 | struct TupleLike(u64, u32); | |
46 | ||
9cc50fc6 SL |
47 | fn test3() -> TupleLike { |
48 | TupleLike(42, 42) | |
49 | } | |
50 | ||
9cc50fc6 SL |
51 | fn test4(x: fn(u64, u32) -> TupleLike) -> (TupleLike, TupleLike) { |
52 | let y = TupleLike; | |
53 | (x(42, 84), y(42, 84)) | |
54 | } | |
55 | ||
9cc50fc6 SL |
56 | fn test5(x: fn(u32) -> Option<u32>) -> (Option<u32>, Option<u32>) { |
57 | let y = Some; | |
58 | (x(42), y(42)) | |
59 | } | |
60 | ||
61 | fn main() { | |
62 | assert_eq!(test1(CEnum::Hello), 42); | |
63 | assert_eq!(test1(CEnum::World), 0); | |
64 | assert_eq!(test2(), Pakd { a: 42, b: 42, c: 42, d: 42, e: () }); | |
65 | assert_eq!(test3(), TupleLike(42, 42)); | |
66 | let t4 = test4(TupleLike); | |
67 | assert_eq!(t4.0, t4.1); | |
68 | let t5 = test5(Some); | |
69 | assert_eq!(t5.0, t5.1); | |
70 | } |