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