]> git.proxmox.com Git - rustc.git/blob - src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / borrowck / borrowck-vec-pattern-nesting.rs
1 #![feature(box_patterns)]
2 #![feature(box_syntax)]
3 #![feature(slice_patterns)]
4
5 fn a() {
6 let mut vec = [box 1, box 2, box 3];
7 match vec {
8 [box ref _a, _, _] => {
9 //~^ NOTE borrow of `vec[_]` occurs here
10 vec[0] = box 4; //~ ERROR cannot assign
11 //~^ NOTE assignment to borrowed `vec[_]` occurs here
12 _a.use_ref();
13 //~^ NOTE borrow later used here
14 }
15 }
16 }
17
18 fn b() {
19 let mut vec = vec![box 1, box 2, box 3];
20 let vec: &mut [Box<isize>] = &mut vec;
21 match vec {
22 &mut [ref _b @ ..] => {
23 //~^ borrow of `vec[_]` occurs here
24 vec[0] = box 4; //~ ERROR cannot assign
25 //~^ NOTE assignment to borrowed `vec[_]` occurs here
26 _b.use_ref();
27 //~^ NOTE borrow later used here
28 }
29 }
30 }
31
32 fn c() {
33 let mut vec = vec![box 1, box 2, box 3];
34 let vec: &mut [Box<isize>] = &mut vec;
35 match vec {
36 //~^ ERROR cannot move out
37 //~| NOTE cannot move out
38 &mut [_a,
39 //~^ NOTE data moved here
40 //~| NOTE move occurs because `_a` has type
41 //~| HELP consider removing the `&mut`
42 ..
43 ] => {
44 }
45 _ => {}
46 }
47 let a = vec[0]; //~ ERROR cannot move out
48 //~| NOTE cannot move out of here
49 //~| NOTE move occurs because
50 //~| HELP consider borrowing here
51 }
52
53 fn d() {
54 let mut vec = vec![box 1, box 2, box 3];
55 let vec: &mut [Box<isize>] = &mut vec;
56 match vec {
57 //~^ ERROR cannot move out
58 //~| NOTE cannot move out
59 &mut [
60 //~^ HELP consider removing the `&mut`
61 _b] => {}
62 //~^ NOTE data moved here
63 //~| NOTE move occurs because `_b` has type
64 _ => {}
65 }
66 let a = vec[0]; //~ ERROR cannot move out
67 //~| NOTE cannot move out of here
68 //~| NOTE move occurs because
69 //~| HELP consider borrowing here
70 }
71
72 fn e() {
73 let mut vec = vec![box 1, box 2, box 3];
74 let vec: &mut [Box<isize>] = &mut vec;
75 match vec {
76 //~^ ERROR cannot move out
77 //~| NOTE cannot move out
78 //~| NOTE move occurs because these variables have types
79 &mut [_a, _b, _c] => {}
80 //~^ NOTE data moved here
81 //~| NOTE and here
82 //~| NOTE and here
83 //~| HELP consider removing the `&mut`
84 _ => {}
85 }
86 let a = vec[0]; //~ ERROR cannot move out
87 //~| NOTE cannot move out of here
88 //~| NOTE move occurs because
89 //~| HELP consider borrowing here
90 }
91
92 fn main() {}
93
94 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
95 impl<T> Fake for T { }