mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
065454dd1d
``` error[E0507]: cannot move out of `val`, a captured variable in an `FnMut` closure --> $DIR/issue-87456-point-to-closure.rs:10:28 | LL | let val = String::new(); | --- captured outer variable LL | LL | take_mut(|| { | -- captured by this `FnMut` closure LL | LL | let _foo: String = val; | ^^^ move occurs because `val` has type `String`, which does not implement the `Copy` trait | help: consider borrowing here | LL | let _foo: String = &val; | + help: consider cloning the value if the performance cost is acceptable | LL | let _foo: String = val.clone(); | ++++++++ ```
98 lines
2.7 KiB
Rust
98 lines
2.7 KiB
Rust
#![feature(box_patterns)]
|
|
|
|
|
|
fn a() {
|
|
let mut vec = [Box::new(1), Box::new(2), Box::new(3)];
|
|
match vec {
|
|
[box ref _a, _, _] => {
|
|
//~^ NOTE `vec[_]` is borrowed here
|
|
vec[0] = Box::new(4); //~ ERROR cannot assign
|
|
//~^ NOTE `vec[_]` is assigned to here
|
|
_a.use_ref();
|
|
//~^ NOTE borrow later used here
|
|
}
|
|
}
|
|
}
|
|
|
|
fn b() {
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
|
match vec {
|
|
&mut [ref _b @ ..] => {
|
|
//~^ `vec[_]` is borrowed here
|
|
vec[0] = Box::new(4); //~ ERROR cannot assign
|
|
//~^ NOTE `vec[_]` is assigned to here
|
|
_b.use_ref();
|
|
//~^ NOTE borrow later used here
|
|
}
|
|
}
|
|
}
|
|
|
|
fn c() {
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
|
match vec {
|
|
//~^ ERROR cannot move out
|
|
//~| NOTE cannot move out
|
|
&mut [_a,
|
|
//~^ NOTE data moved here
|
|
//~| NOTE move occurs because `_a` has type
|
|
//~| HELP consider removing the mutable borrow
|
|
..
|
|
] => {
|
|
}
|
|
_ => {}
|
|
}
|
|
let a = vec[0]; //~ ERROR cannot move out
|
|
//~| NOTE cannot move out of here
|
|
//~| NOTE move occurs because
|
|
//~| HELP consider borrowing here
|
|
//~| HELP consider cloning
|
|
}
|
|
|
|
fn d() {
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
|
match vec {
|
|
//~^ ERROR cannot move out
|
|
//~| NOTE cannot move out
|
|
&mut [
|
|
//~^ HELP consider removing the mutable borrow
|
|
_b] => {}
|
|
//~^ NOTE data moved here
|
|
//~| NOTE move occurs because `_b` has type
|
|
_ => {}
|
|
}
|
|
let a = vec[0]; //~ ERROR cannot move out
|
|
//~| NOTE cannot move out of here
|
|
//~| NOTE move occurs because
|
|
//~| HELP consider borrowing here
|
|
//~| HELP consider cloning
|
|
}
|
|
|
|
fn e() {
|
|
let mut vec = vec![Box::new(1), Box::new(2), Box::new(3)];
|
|
let vec: &mut [Box<isize>] = &mut vec;
|
|
match vec {
|
|
//~^ ERROR cannot move out
|
|
//~| NOTE cannot move out
|
|
//~| NOTE move occurs because these variables have types
|
|
&mut [_a, _b, _c] => {}
|
|
//~^ NOTE data moved here
|
|
//~| NOTE and here
|
|
//~| NOTE and here
|
|
//~| HELP consider removing the mutable borrow
|
|
_ => {}
|
|
}
|
|
let a = vec[0]; //~ ERROR cannot move out
|
|
//~| NOTE cannot move out of here
|
|
//~| NOTE move occurs because
|
|
//~| HELP consider borrowing here
|
|
//~| HELP consider cloning
|
|
}
|
|
|
|
fn main() {}
|
|
|
|
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
|
|
impl<T> Fake for T { }
|