]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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)] | |
85aaf69f | 12 | #![feature(box_patterns)] |
1a4d82fc | 13 | #![feature(box_syntax)] |
c34b1796 | 14 | #![feature(slice_patterns)] |
1a4d82fc | 15 | |
223e47cc | 16 | fn a() { |
85aaf69f | 17 | let mut vec = [box 1, box 2, box 3]; |
223e47cc | 18 | match vec { |
1a4d82fc | 19 | [box ref _a, _, _] => { |
54a0048b | 20 | //~^ borrow of `vec[..]` occurs here |
1a4d82fc | 21 | vec[0] = box 4; //~ ERROR cannot assign |
223e47cc | 22 | } |
223e47cc LB |
23 | } |
24 | } | |
25 | ||
26 | fn b() { | |
85aaf69f SL |
27 | let mut vec = vec!(box 1, box 2, box 3); |
28 | let vec: &mut [Box<isize>] = &mut vec; | |
1a4d82fc JJ |
29 | match vec { |
30 | [_b..] => { | |
54a0048b | 31 | //~^ borrow of `vec[..]` occurs here |
1a4d82fc JJ |
32 | vec[0] = box 4; //~ ERROR cannot assign |
33 | } | |
34 | } | |
35 | } | |
36 | ||
37 | fn c() { | |
85aaf69f SL |
38 | let mut vec = vec!(box 1, box 2, box 3); |
39 | let vec: &mut [Box<isize>] = &mut vec; | |
223e47cc | 40 | match vec { |
1a4d82fc JJ |
41 | [_a, //~ ERROR cannot move out |
42 | _b..] => { //~^ NOTE attempting to move value to here | |
43 | ||
44 | // Note: `_a` is *moved* here, but `b` is borrowing, | |
45 | // hence illegal. | |
46 | // | |
47 | // See comment in middle/borrowck/gather_loans/mod.rs | |
48 | // in the case covering these sorts of vectors. | |
223e47cc | 49 | } |
1a4d82fc JJ |
50 | _ => {} |
51 | } | |
52 | let a = vec[0]; //~ ERROR cannot move out | |
54a0048b | 53 | //~^ NOTE attempting to move value to here |
1a4d82fc JJ |
54 | } |
55 | ||
56 | fn d() { | |
85aaf69f SL |
57 | let mut vec = vec!(box 1, box 2, box 3); |
58 | let vec: &mut [Box<isize>] = &mut vec; | |
1a4d82fc JJ |
59 | match vec { |
60 | [_a.., //~ ERROR cannot move out | |
61 | _b] => {} //~ NOTE attempting to move value to here | |
62 | _ => {} | |
63 | } | |
64 | let a = vec[0]; //~ ERROR cannot move out | |
54a0048b | 65 | //~^ NOTE attempting to move value to here |
1a4d82fc JJ |
66 | } |
67 | ||
68 | fn e() { | |
85aaf69f SL |
69 | let mut vec = vec!(box 1, box 2, box 3); |
70 | let vec: &mut [Box<isize>] = &mut vec; | |
1a4d82fc JJ |
71 | match vec { |
72 | [_a, _b, _c] => {} //~ ERROR cannot move out | |
73 | //~^ NOTE attempting to move value to here | |
74 | //~^^ NOTE and here | |
75 | //~^^^ NOTE and here | |
76 | _ => {} | |
223e47cc | 77 | } |
1a4d82fc JJ |
78 | let a = vec[0]; //~ ERROR cannot move out |
79 | //~^ NOTE attempting to move value to here | |
223e47cc LB |
80 | } |
81 | ||
82 | fn main() {} |