]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-match-binding-is-assignment.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-match-binding-is-assignment.rs
1 // Test that immutable pattern bindings cannot be reassigned.
2
3 enum E {
4     Foo(isize)
5 }
6
7 struct S {
8     bar: isize,
9 }
10
11 pub fn main() {
12     match 1 {
13         x => {
14             x += 1; //~ ERROR [E0384]
15         }
16     }
17
18     match E::Foo(1) {
19         E::Foo(x) => {
20             x += 1; //~ ERROR [E0384]
21         }
22     }
23
24     match (S { bar: 1 }) {
25         S { bar: x } => {
26             x += 1; //~ ERROR [E0384]
27         }
28     }
29
30     match (1,) {
31         (x,) => {
32             x += 1; //~ ERROR [E0384]
33         }
34     }
35
36     match [1,2,3] {
37         [x,_,_] => {
38             x += 1; //~ ERROR [E0384]
39         }
40     }
41 }