]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/packed/packed-struct-match.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / packed / packed-struct-match.rs
1 // Copyright 2013 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
11 // run-pass
12 #![feature(repr_packed)]
13
14 #[repr(packed)]
15 struct Foo1 {
16 bar: u8,
17 baz: usize
18 }
19
20 #[repr(packed(2))]
21 struct Foo2 {
22 bar: u8,
23 baz: usize
24 }
25
26 #[repr(C, packed(4))]
27 struct Foo4C {
28 bar: u8,
29 baz: usize
30 }
31
32 pub fn main() {
33 let foo1 = Foo1 { bar: 1, baz: 2 };
34 match foo1 {
35 Foo1 {bar, baz} => {
36 assert_eq!(bar, 1);
37 assert_eq!(baz, 2);
38 }
39 }
40
41 let foo2 = Foo2 { bar: 1, baz: 2 };
42 match foo2 {
43 Foo2 {bar, baz} => {
44 assert_eq!(bar, 1);
45 assert_eq!(baz, 2);
46 }
47 }
48
49 let foo4 = Foo4C { bar: 1, baz: 2 };
50 match foo4 {
51 Foo4C {bar, baz} => {
52 assert_eq!(bar, 1);
53 assert_eq!(baz, 2);
54 }
55 }
56 }