]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / compile-fail / borrowck / 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 #![feature(advanced_slice_patterns)]
12 #![feature(box_patterns)]
13 #![feature(box_syntax)]
14 #![feature(slice_patterns)]
15
16 fn a() {
17 let mut vec = [box 1, box 2, box 3];
18 match vec {
19 [box ref _a, _, _] => {
20 //~^ borrow of `vec[..]` occurs here
21 vec[0] = box 4; //~ ERROR cannot assign
22 //~^ assignment to borrowed `vec[..]` occurs here
23 }
24 }
25 }
26
27 fn b() {
28 let mut vec = vec!(box 1, box 2, box 3);
29 let vec: &mut [Box<isize>] = &mut vec;
30 match vec {
31 &mut [ref _b..] => {
32 //~^ borrow of `vec[..]` occurs here
33 vec[0] = box 4; //~ ERROR cannot assign
34 //~^ assignment to borrowed `vec[..]` occurs here
35 }
36 }
37 }
38
39 fn c() {
40 let mut vec = vec!(box 1, box 2, box 3);
41 let vec: &mut [Box<isize>] = &mut vec;
42 match vec {
43 &mut [_a, //~ ERROR cannot move out
44 //~| cannot move out
45 //~| to prevent move
46 ..
47 ] => {
48 // Note: `_a` is *moved* here, but `b` is borrowing,
49 // hence illegal.
50 //
51 // See comment in middle/borrowck/gather_loans/mod.rs
52 // in the case covering these sorts of vectors.
53 }
54 _ => {}
55 }
56 let a = vec[0]; //~ ERROR cannot move out
57 //~^ NOTE to prevent move
58 //~| cannot move out of here
59 }
60
61 fn d() {
62 let mut vec = vec!(box 1, box 2, box 3);
63 let vec: &mut [Box<isize>] = &mut vec;
64 match vec {
65 &mut [ //~ ERROR cannot move out
66 //~^ cannot move out
67 _b] => {} //~ NOTE to prevent move
68 _ => {}
69 }
70 let a = vec[0]; //~ ERROR cannot move out
71 //~^ NOTE to prevent move
72 //~| cannot move out of here
73 }
74
75 fn e() {
76 let mut vec = vec!(box 1, box 2, box 3);
77 let vec: &mut [Box<isize>] = &mut vec;
78 match vec {
79 &mut [_a, _b, _c] => {} //~ ERROR cannot move out
80 //~| cannot move out
81 //~| NOTE to prevent move
82 //~| NOTE and here
83 //~| NOTE and here
84 _ => {}
85 }
86 let a = vec[0]; //~ ERROR cannot move out
87 //~^ NOTE to prevent move
88 //~| cannot move out of here
89 }
90
91 fn main() {}