]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/expr-match-struct.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / expr-match-struct.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
12
13
14
15 // Tests for match as expressions resulting in struct types
16 #[derive(Copy)]
17 struct R { i: int }
18
19 fn test_rec() {
20     let rs = match true { true => R {i: 100}, _ => panic!() };
21     assert_eq!(rs.i, 100);
22 }
23
24 #[derive(Copy, Show)]
25 enum mood { happy, sad, }
26
27 impl PartialEq for mood {
28     fn eq(&self, other: &mood) -> bool {
29         ((*self) as uint) == ((*other) as uint)
30     }
31     fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
32 }
33
34 fn test_tag() {
35     let rs = match true { true => { mood::happy } false => { mood::sad } };
36     assert_eq!(rs, mood::happy);
37 }
38
39 pub fn main() { test_rec(); test_tag(); }