]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/mut-in-ident-patterns.rs
d3ae80861f231c5f29aaa57ed211104b7c59c5b8
[rustc.git] / src / test / run-pass / mut-in-ident-patterns.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 trait Foo {
12 fn foo(&self, mut x: int) -> int {
13 let val = x;
14 x = 37 * x;
15 val + x
16 }
17 }
18
19 struct X;
20 impl Foo for X {}
21
22 pub fn main() {
23 let (a, mut b) = (23, 4);
24 assert_eq!(a, 23);
25 assert_eq!(b, 4);
26 b = a + b;
27 assert_eq!(b, 27);
28
29
30 assert_eq!(X.foo(2), 76);
31
32 enum Bar {
33 Foo(int),
34 Baz(f32, u8)
35 }
36
37 let (x, mut y) = (32, Bar::Foo(21));
38
39 match x {
40 mut z @ 32 => {
41 assert_eq!(z, 32);
42 z = 34;
43 assert_eq!(z, 34);
44 }
45 _ => {}
46 }
47
48 check_bar(&y);
49 y = Bar::Baz(10.0, 3);
50 check_bar(&y);
51
52 fn check_bar(y: &Bar) {
53 match y {
54 &Bar::Foo(a) => {
55 assert_eq!(a, 21);
56 }
57 &Bar::Baz(a, b) => {
58 assert_eq!(a, 10.0);
59 assert_eq!(b, 3);
60 }
61 }
62 }
63
64 fn foo1((x, mut y): (f64, int), mut z: int) -> int {
65 y = 2 * 6;
66 z = y + (x as int);
67 y - z
68 }
69
70 struct A {
71 x: int
72 }
73 let A { x: mut x } = A { x: 10 };
74 assert_eq!(x, 10);
75 x = 30;
76 assert_eq!(x, 30);
77
78 (|A { x: mut t }: A| { t = t+1; t })(A { x: 34 });
79
80 }