]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | ||
c34b1796 AL |
11 | // pretty-expanded FIXME #23616 |
12 | ||
1a4d82fc | 13 | trait Foo { |
c34b1796 | 14 | fn foo(&self, mut x: isize) -> isize { |
1a4d82fc JJ |
15 | let val = x; |
16 | x = 37 * x; | |
17 | val + x | |
18 | } | |
19 | } | |
20 | ||
21 | struct X; | |
22 | impl Foo for X {} | |
23 | ||
24 | pub fn main() { | |
85aaf69f | 25 | let (a, mut b) = (23, 4); |
1a4d82fc JJ |
26 | assert_eq!(a, 23); |
27 | assert_eq!(b, 4); | |
28 | b = a + b; | |
29 | assert_eq!(b, 27); | |
30 | ||
31 | ||
32 | assert_eq!(X.foo(2), 76); | |
33 | ||
34 | enum Bar { | |
c34b1796 | 35 | Foo(isize), |
1a4d82fc JJ |
36 | Baz(f32, u8) |
37 | } | |
38 | ||
85aaf69f | 39 | let (x, mut y) = (32, Bar::Foo(21)); |
1a4d82fc JJ |
40 | |
41 | match x { | |
42 | mut z @ 32 => { | |
43 | assert_eq!(z, 32); | |
44 | z = 34; | |
45 | assert_eq!(z, 34); | |
46 | } | |
47 | _ => {} | |
48 | } | |
49 | ||
50 | check_bar(&y); | |
51 | y = Bar::Baz(10.0, 3); | |
52 | check_bar(&y); | |
53 | ||
54 | fn check_bar(y: &Bar) { | |
55 | match y { | |
56 | &Bar::Foo(a) => { | |
57 | assert_eq!(a, 21); | |
58 | } | |
59 | &Bar::Baz(a, b) => { | |
60 | assert_eq!(a, 10.0); | |
61 | assert_eq!(b, 3); | |
62 | } | |
63 | } | |
64 | } | |
65 | ||
c34b1796 | 66 | fn foo1((x, mut y): (f64, isize), mut z: isize) -> isize { |
1a4d82fc | 67 | y = 2 * 6; |
c34b1796 | 68 | z = y + (x as isize); |
1a4d82fc JJ |
69 | y - z |
70 | } | |
71 | ||
72 | struct A { | |
c34b1796 | 73 | x: isize |
1a4d82fc JJ |
74 | } |
75 | let A { x: mut x } = A { x: 10 }; | |
76 | assert_eq!(x, 10); | |
77 | x = 30; | |
78 | assert_eq!(x, 30); | |
79 | ||
85aaf69f | 80 | (|A { x: mut t }: A| { t = t+1; t })(A { x: 34 }); |
1a4d82fc JJ |
81 | |
82 | } |