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