]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / 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(box_patterns)]
12 #![feature(box_syntax)]
13 #![feature(slice_patterns)]
14
15 fn a() {
16     let mut vec = [box 1, box 2, box 3];
17     match vec {
18         [box ref _a, _, _] => {
19         //~^ borrow of `vec[..]` occurs here
20             vec[0] = box 4; //~ ERROR cannot assign
21             //~^ assignment to borrowed `vec[..]` occurs here
22             _a.use_ref();
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             _b.use_ref();
36         }
37     }
38 }
39
40 fn c() {
41     let mut vec = vec![box 1, box 2, box 3];
42     let vec: &mut [Box<isize>] = &mut vec;
43     match vec {
44         &mut [_a, //~ ERROR cannot move out
45             //~| cannot move out
46             //~| to prevent move
47             ..
48         ] => {
49             // Note: `_a` is *moved* here, but `b` is borrowing,
50             // hence illegal.
51             //
52             // See comment in middle/borrowck/gather_loans/mod.rs
53             // in the case covering these sorts of vectors.
54         }
55         _ => {}
56     }
57     let a = vec[0]; //~ ERROR cannot move out
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] => {}
68         _ => {}
69     }
70     let a = vec[0]; //~ ERROR cannot move out
71     //~| cannot move out of here
72 }
73
74 fn e() {
75     let mut vec = vec![box 1, box 2, box 3];
76     let vec: &mut [Box<isize>] = &mut vec;
77     match vec {
78         &mut [_a, _b, _c] => {}  //~ ERROR cannot move out
79         //~| cannot move out
80         _ => {}
81     }
82     let a = vec[0]; //~ ERROR cannot move out
83     //~| cannot move out of here
84 }
85
86 fn main() {}
87
88 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
89 impl<T> Fake for T { }