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