]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/borrowck-vec-pattern-nesting.rs
a3b0c0ea3591d6e9bfcc8a85873d26e7fc6afb77
[rust.git] / src / test / compile-fail / borrowck-vec-pattern-nesting.rs
1 // Copyright 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
11 fn a() {
12     let mut vec = [~1, ~2, ~3];
13     match vec {
14         [~ref _a, _, _] => {
15             vec[0] = ~4; //~ ERROR cannot assign
16         }
17     }
18 }
19
20 fn b() {
21     let mut vec = vec!(~1, ~2, ~3);
22     let vec: &mut [~int] = vec;
23     match vec {
24         [.._b] => {
25             vec[0] = ~4; //~ ERROR cannot assign
26         }
27     }
28 }
29
30 fn c() {
31     let mut vec = vec!(~1, ~2, ~3);
32     let vec: &mut [~int] = vec;
33     match vec {
34         [_a, .._b] => {
35             //~^ ERROR cannot move out
36
37             // Note: `_a` is *moved* here, but `b` is borrowing,
38             // hence illegal.
39             //
40             // See comment in middle/borrowck/gather_loans/mod.rs
41             // in the case covering these sorts of vectors.
42         }
43         _ => {}
44     }
45     let a = vec[0]; //~ ERROR cannot move out
46 }
47
48 fn d() {
49     let mut vec = vec!(~1, ~2, ~3);
50     let vec: &mut [~int] = vec;
51     match vec {
52         [.._a, _b] => {
53             //~^ ERROR cannot move out
54         }
55         _ => {}
56     }
57     let a = vec[0]; //~ ERROR cannot move out
58 }
59
60 fn e() {
61     let mut vec = vec!(~1, ~2, ~3);
62     let vec: &mut [~int] = vec;
63     match vec {
64         [_a, _b, _c] => {}  //~ ERROR cannot move out
65         //~^ ERROR cannot move out
66         //~^^ ERROR cannot move out
67         _ => {}
68     }
69     let a = vec[0]; //~ ERROR cannot move out
70 }
71
72 fn main() {}