]> git.proxmox.com Git - rustc.git/blame - src/test/ui/binding/mut-in-ident-patterns.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / binding / mut-in-ident-patterns.rs
CommitLineData
b7449926 1// run-pass
0bf4aa26
XL
2#![allow(dead_code)]
3#![allow(unused_assignments)]
b7449926
XL
4#![allow(non_camel_case_types)]
5#![allow(non_shorthand_field_patterns)]
c34b1796 6
1a4d82fc 7trait Foo {
c34b1796 8 fn foo(&self, mut x: isize) -> isize {
1a4d82fc
JJ
9 let val = x;
10 x = 37 * x;
11 val + x
12 }
13}
14
15struct X;
16impl Foo for X {}
17
18pub fn main() {
85aaf69f 19 let (a, mut b) = (23, 4);
1a4d82fc
JJ
20 assert_eq!(a, 23);
21 assert_eq!(b, 4);
22 b = a + b;
23 assert_eq!(b, 27);
24
25
26 assert_eq!(X.foo(2), 76);
27
28 enum Bar {
c34b1796 29 Foo(isize),
1a4d82fc
JJ
30 Baz(f32, u8)
31 }
32
85aaf69f 33 let (x, mut y) = (32, Bar::Foo(21));
1a4d82fc
JJ
34
35 match x {
36 mut z @ 32 => {
37 assert_eq!(z, 32);
38 z = 34;
39 assert_eq!(z, 34);
40 }
41 _ => {}
42 }
43
44 check_bar(&y);
45 y = Bar::Baz(10.0, 3);
46 check_bar(&y);
47
48 fn check_bar(y: &Bar) {
49 match y {
50 &Bar::Foo(a) => {
51 assert_eq!(a, 21);
52 }
53 &Bar::Baz(a, b) => {
54 assert_eq!(a, 10.0);
55 assert_eq!(b, 3);
56 }
57 }
58 }
59
c34b1796 60 fn foo1((x, mut y): (f64, isize), mut z: isize) -> isize {
1a4d82fc 61 y = 2 * 6;
c34b1796 62 z = y + (x as isize);
1a4d82fc
JJ
63 y - z
64 }
65
66 struct A {
c34b1796 67 x: isize
1a4d82fc
JJ
68 }
69 let A { x: mut x } = A { x: 10 };
70 assert_eq!(x, 10);
71 x = 30;
72 assert_eq!(x, 30);
73
85aaf69f 74 (|A { x: mut t }: A| { t = t+1; t })(A { x: 34 });
1a4d82fc
JJ
75
76}