2015-02-10 21:52:00 +00:00
|
|
|
#![feature(box_patterns)]
|
2021-08-25 00:39:40 +00:00
|
|
|
|
2014-05-06 01:56:44 +00:00
|
|
|
|
2013-01-25 03:33:48 +00:00
|
|
|
fn a() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut vec = [Box::new(1), Box::new(2), Box::new(3)];
|
2013-01-25 03:33:48 +00:00
|
|
|
match vec {
|
2014-05-06 01:56:44 +00:00
|
|
|
[box ref _a, _, _] => {
|
2023-01-15 03:06:44 +00:00
|
|
|
//~^ NOTE `vec[_]` is borrowed here
|
2021-08-25 00:39:40 +00:00
|
|
|
vec[0] = Box::new(4); //~ ERROR cannot assign
|
2023-01-15 03:06:44 +00:00
|
|
|
//~^ NOTE `vec[_]` is assigned to here
|
2018-05-31 10:58:10 +00:00
|
|
|
_a.use_ref();
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ NOTE borrow later used here
|
2013-01-25 03:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn b() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
2015-02-02 02:53:25 +00:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-01-25 03:33:48 +00:00
|
|
|
match vec {
|
2019-07-07 23:47:46 +00:00
|
|
|
&mut [ref _b @ ..] => {
|
2023-01-15 03:06:44 +00:00
|
|
|
//~^ `vec[_]` is borrowed here
|
2021-08-25 00:39:40 +00:00
|
|
|
vec[0] = Box::new(4); //~ ERROR cannot assign
|
2023-01-15 03:06:44 +00:00
|
|
|
//~^ NOTE `vec[_]` is assigned to here
|
2018-05-31 10:58:10 +00:00
|
|
|
_b.use_ref();
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ NOTE borrow later used here
|
2013-01-25 03:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 19:11:20 +00:00
|
|
|
fn c() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
2015-02-02 02:53:25 +00:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-06-20 19:11:20 +00:00
|
|
|
match vec {
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR cannot move out
|
|
|
|
//~| NOTE cannot move out
|
|
|
|
&mut [_a,
|
|
|
|
//~^ NOTE data moved here
|
|
|
|
//~| NOTE move occurs because `_a` has type
|
2022-12-08 17:02:54 +00:00
|
|
|
//~| HELP consider removing the mutable borrow
|
2016-03-11 10:54:59 +00:00
|
|
|
..
|
|
|
|
] => {
|
2013-06-20 19:11:20 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2014-02-13 17:46:46 +00:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2019-04-22 07:40:08 +00:00
|
|
|
//~| NOTE cannot move out of here
|
2019-05-05 11:02:32 +00:00
|
|
|
//~| NOTE move occurs because
|
2019-04-22 07:40:08 +00:00
|
|
|
//~| HELP consider borrowing here
|
2013-06-20 19:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn d() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
2015-02-02 02:53:25 +00:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-06-20 19:11:20 +00:00
|
|
|
match vec {
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR cannot move out
|
|
|
|
//~| NOTE cannot move out
|
|
|
|
&mut [
|
2022-12-08 17:02:54 +00:00
|
|
|
//~^ HELP consider removing the mutable borrow
|
2017-12-10 20:29:24 +00:00
|
|
|
_b] => {}
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ NOTE data moved here
|
|
|
|
//~| NOTE move occurs because `_b` has type
|
2013-06-20 19:11:20 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2014-02-13 17:46:46 +00:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2019-04-22 07:40:08 +00:00
|
|
|
//~| NOTE cannot move out of here
|
2019-05-05 11:02:32 +00:00
|
|
|
//~| NOTE move occurs because
|
2019-04-22 07:40:08 +00:00
|
|
|
//~| HELP consider borrowing here
|
2013-06-20 19:11:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn e() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
2015-02-02 02:53:25 +00:00
|
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
2013-06-20 19:11:20 +00:00
|
|
|
match vec {
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR cannot move out
|
|
|
|
//~| NOTE cannot move out
|
2019-11-25 20:32:57 +00:00
|
|
|
//~| NOTE move occurs because these variables have types
|
2019-04-22 07:40:08 +00:00
|
|
|
&mut [_a, _b, _c] => {}
|
|
|
|
//~^ NOTE data moved here
|
|
|
|
//~| NOTE and here
|
|
|
|
//~| NOTE and here
|
2022-12-08 17:02:54 +00:00
|
|
|
//~| HELP consider removing the mutable borrow
|
2013-06-20 19:11:20 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2014-02-13 17:46:46 +00:00
|
|
|
let a = vec[0]; //~ ERROR cannot move out
|
2019-04-22 07:40:08 +00:00
|
|
|
//~| NOTE cannot move out of here
|
2019-05-05 11:02:32 +00:00
|
|
|
//~| NOTE move occurs because
|
2019-04-22 07:40:08 +00:00
|
|
|
//~| HELP consider borrowing here
|
2013-06-20 19:11:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 03:33:48 +00:00
|
|
|
fn main() {}
|
2018-05-31 10:58:10 +00:00
|
|
|
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
|
|
impl<T> Fake for T { }
|