]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/struct-aliases.rs
Auto merge of #27169 - huonw:simd, r=alexcrichton
[rust.git] / src / test / run-pass / struct-aliases.rs
1 // Copyright 2012 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 use std::mem;
12
13 struct S {
14     x: isize,
15     y: isize,
16 }
17
18 type S2 = S;
19
20 struct S3<U,V> {
21     x: U,
22     y: V
23 }
24
25 type S4<U> = S3<U, char>;
26
27 fn main() {
28     let s = S2 {
29         x: 1,
30         y: 2,
31     };
32     match s {
33         S2 {
34             x: x,
35             y: y
36         } => {
37             assert_eq!(x, 1);
38             assert_eq!(y, 2);
39         }
40     }
41     // check that generics can be specified from the pattern
42     let s = S4 {
43         x: 4,
44         y: 'a'
45     };
46     match s {
47         S4::<u8> {
48             x: x,
49             y: y
50         } => {
51             assert_eq!(x, 4);
52             assert_eq!(y, 'a');
53             assert_eq!(mem::size_of_val(&x), 1);
54         }
55     };
56     // check that generics can be specified from the constructor
57     let s = S4::<u16> {
58         x: 5,
59         y: 'b'
60     };
61     match s {
62         S4 {
63             x: x,
64             y: y
65         } => {
66             assert_eq!(x, 5);
67             assert_eq!(y, 'b');
68             assert_eq!(mem::size_of_val(&x), 2);
69         }
70     };
71 }