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