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