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