]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-5530.rs
auto merge of #8350 : dim-an/rust/fix-struct-match, r=pcwalton
[rust.git] / src / test / run-pass / issue-5530.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 enum Enum {
12     Foo { foo: uint },
13     Bar { bar: uint }
14 }
15
16 fn fun1(e1: &Enum, e2: &Enum) -> uint {
17     match (e1, e2) {
18         (&Foo { foo: _ }, &Foo { foo: _ }) => 0,
19         (&Foo { foo: _ }, &Bar { bar: _ }) => 1,
20         (&Bar { bar: _ }, &Bar { bar: _ }) => 2,
21         (&Bar { bar: _ }, &Foo { foo: _ }) => 3,
22     }
23 }
24
25 fn fun2(e1: &Enum, e2: &Enum) -> uint {
26     match (e1, e2) {
27         (&Foo { foo: _ }, &Foo { foo: _ }) => 0,
28         (&Foo { foo: _ }, _              ) => 1,
29         (&Bar { bar: _ }, &Bar { bar: _ }) => 2,
30         (&Bar { bar: _ }, _              ) => 3,
31     }
32 }
33
34 pub fn main() {
35     let foo = Foo { foo: 1 };
36     let bar = Bar { bar: 1 };
37
38     assert_eq!(fun1(&foo, &foo), 0);
39     assert_eq!(fun1(&foo, &bar), 1);
40     assert_eq!(fun1(&bar, &bar), 2);
41     assert_eq!(fun1(&bar, &foo), 3);
42
43     assert_eq!(fun2(&foo, &foo), 0);
44     assert_eq!(fun2(&foo, &bar), 1); // fun2 returns 0
45     assert_eq!(fun2(&bar, &bar), 2);
46     assert_eq!(fun2(&bar, &foo), 3); // fun2 returns 2
47 }