]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/borrowck/borrowck-match-binding-is-assignment.rs
New upstream version 1.26.0+dfsg1
[rustc.git] / src / test / compile-fail / borrowck / borrowck-match-binding-is-assignment.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2012-2014 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
ea8adc8c 11// revisions: ast mir
ff7c6d11 12//[mir]compile-flags: -Z borrowck=mir
ea8adc8c 13
1a4d82fc
JJ
14// Test that immutable pattern bindings cannot be reassigned.
15
16enum E {
17 Foo(isize)
18}
19
20struct S {
21 bar: isize,
22}
23
24pub fn main() {
85aaf69f 25 match 1 {
1a4d82fc 26 x => {
abe05a73 27 x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x`
ff7c6d11 28 //[mir]~^ ERROR [E0384]
1a4d82fc
JJ
29 }
30 }
31
32 match E::Foo(1) {
33 E::Foo(x) => {
abe05a73 34 x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x`
ff7c6d11 35 //[mir]~^ ERROR [E0384]
1a4d82fc
JJ
36 }
37 }
38
39 match (S { bar: 1 }) {
40 S { bar: x } => {
abe05a73 41 x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x`
ff7c6d11 42 //[mir]~^ ERROR [E0384]
1a4d82fc
JJ
43 }
44 }
45
85aaf69f 46 match (1,) {
1a4d82fc 47 (x,) => {
abe05a73 48 x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x`
ff7c6d11 49 //[mir]~^ ERROR [E0384]
1a4d82fc
JJ
50 }
51 }
52
85aaf69f 53 match [1,2,3] {
1a4d82fc 54 [x,_,_] => {
abe05a73 55 x += 1; //[ast]~ ERROR cannot assign twice to immutable variable `x`
ff7c6d11 56 //[mir]~^ ERROR [E0384]
1a4d82fc
JJ
57 }
58 }
59}