mirror of https://github.com/rust-lang/rust.git
More move error suggestions to clone
``` 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(); | ++++++++ ```
This commit is contained in:
parent
10c2fbec24
commit
065454dd1d
|
@ -444,6 +444,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
None => "value".to_string(),
|
None => "value".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(expr) = self.find_expr(span) {
|
||||||
|
self.suggest_cloning(err, place_ty, expr, span);
|
||||||
|
}
|
||||||
|
|
||||||
err.subdiagnostic(
|
err.subdiagnostic(
|
||||||
self.dcx(),
|
self.dcx(),
|
||||||
crate::session_diagnostics::TypeNoCopy::Label {
|
crate::session_diagnostics::TypeNoCopy::Label {
|
||||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
||||||
|
|
||||||
match x {
|
match x {
|
||||||
Some(ref y) => {
|
Some(ref y) => {
|
||||||
let _b = y; //~ ERROR cannot move out
|
let _b = y.clone(); //~ ERROR cannot move out
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@ help: consider removing the dereference here
|
||||||
LL - let _b = *y;
|
LL - let _b = *y;
|
||||||
LL + let _b = y;
|
LL + let _b = y;
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let _b = *y;
|
||||||
|
LL + let _b = y.clone();
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@ help: consider removing the dereference here
|
||||||
LL - let y = *x;
|
LL - let y = *x;
|
||||||
LL + let y = x;
|
LL + let y = x;
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let y = *x;
|
||||||
|
LL + let y = x.clone();
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@ help: consider removing the dereference here
|
||||||
LL - let _x = *Rc::new("hi".to_string());
|
LL - let _x = *Rc::new("hi".to_string());
|
||||||
LL + let _x = Rc::new("hi".to_string());
|
LL + let _x = Rc::new("hi".to_string());
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let _x = *Rc::new("hi".to_string());
|
||||||
|
LL + let _x = Rc::new("hi".to_string()).clone();
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let bad = &v[0];
|
LL | let bad = &v[0];
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let bad = v[0].clone();
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ fn c() {
|
||||||
//~| NOTE cannot move out of here
|
//~| NOTE cannot move out of here
|
||||||
//~| NOTE move occurs because
|
//~| NOTE move occurs because
|
||||||
//~| HELP consider borrowing here
|
//~| HELP consider borrowing here
|
||||||
|
//~| HELP consider cloning
|
||||||
}
|
}
|
||||||
|
|
||||||
fn d() {
|
fn d() {
|
||||||
|
@ -66,6 +67,7 @@ fn d() {
|
||||||
//~| NOTE cannot move out of here
|
//~| NOTE cannot move out of here
|
||||||
//~| NOTE move occurs because
|
//~| NOTE move occurs because
|
||||||
//~| HELP consider borrowing here
|
//~| HELP consider borrowing here
|
||||||
|
//~| HELP consider cloning
|
||||||
}
|
}
|
||||||
|
|
||||||
fn e() {
|
fn e() {
|
||||||
|
@ -86,6 +88,7 @@ fn e() {
|
||||||
//~| NOTE cannot move out of here
|
//~| NOTE cannot move out of here
|
||||||
//~| NOTE move occurs because
|
//~| NOTE move occurs because
|
||||||
//~| HELP consider borrowing here
|
//~| HELP consider borrowing here
|
||||||
|
//~| HELP consider cloning
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -53,9 +53,13 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let a = &vec[0];
|
LL | let a = &vec[0];
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let a = vec[0].clone();
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
||||||
--> $DIR/borrowck-vec-pattern-nesting.rs:55:11
|
--> $DIR/borrowck-vec-pattern-nesting.rs:56:11
|
||||||
|
|
|
|
||||||
LL | match vec {
|
LL | match vec {
|
||||||
| ^^^ cannot move out of here
|
| ^^^ cannot move out of here
|
||||||
|
@ -73,7 +77,7 @@ LL + [
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
||||||
--> $DIR/borrowck-vec-pattern-nesting.rs:65:13
|
--> $DIR/borrowck-vec-pattern-nesting.rs:66:13
|
||||||
|
|
|
|
||||||
LL | let a = vec[0];
|
LL | let a = vec[0];
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -85,9 +89,13 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let a = &vec[0];
|
LL | let a = &vec[0];
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let a = vec[0].clone();
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
||||||
--> $DIR/borrowck-vec-pattern-nesting.rs:74:11
|
--> $DIR/borrowck-vec-pattern-nesting.rs:76:11
|
||||||
|
|
|
|
||||||
LL | match vec {
|
LL | match vec {
|
||||||
| ^^^ cannot move out of here
|
| ^^^ cannot move out of here
|
||||||
|
@ -106,7 +114,7 @@ LL + [_a, _b, _c] => {}
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
|
||||||
--> $DIR/borrowck-vec-pattern-nesting.rs:85:13
|
--> $DIR/borrowck-vec-pattern-nesting.rs:87:13
|
||||||
|
|
|
|
||||||
LL | let a = vec[0];
|
LL | let a = vec[0];
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -118,6 +126,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let a = &vec[0];
|
LL | let a = &vec[0];
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let a = vec[0].clone();
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 8 previous errors
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let _foo: String = &val;
|
LL | let _foo: String = &val;
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let _foo: String = val.clone();
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | &x
|
LL | &x
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | x.clone()
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 17 previous errors
|
error: aborting due to 17 previous errors
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let e = &f.v[0];
|
LL | let e = &f.v[0];
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let e = f.v[0].clone();
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@ help: consider removing the dereference here
|
||||||
LL - let x = { *r };
|
LL - let x = { *r };
|
||||||
LL + let x = { r };
|
LL + let x = { r };
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let x = { *r };
|
||||||
|
LL + let x = { r.clone() };
|
||||||
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
||||||
--> $DIR/cannot-move-block-spans.rs:6:22
|
--> $DIR/cannot-move-block-spans.rs:6:22
|
||||||
|
@ -21,6 +26,11 @@ help: consider removing the dereference here
|
||||||
LL - let y = unsafe { *r };
|
LL - let y = unsafe { *r };
|
||||||
LL + let y = unsafe { r };
|
LL + let y = unsafe { r };
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let y = unsafe { *r };
|
||||||
|
LL + let y = unsafe { r.clone() };
|
||||||
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
||||||
--> $DIR/cannot-move-block-spans.rs:7:26
|
--> $DIR/cannot-move-block-spans.rs:7:26
|
||||||
|
@ -33,6 +43,11 @@ help: consider removing the dereference here
|
||||||
LL - let z = loop { break *r; };
|
LL - let z = loop { break *r; };
|
||||||
LL + let z = loop { break r; };
|
LL + let z = loop { break r; };
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let z = loop { break *r; };
|
||||||
|
LL + let z = loop { break r.clone(); };
|
||||||
|
|
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[String; 2]`, a non-copy array
|
error[E0508]: cannot move out of type `[String; 2]`, a non-copy array
|
||||||
--> $DIR/cannot-move-block-spans.rs:11:15
|
--> $DIR/cannot-move-block-spans.rs:11:15
|
||||||
|
@ -47,6 +62,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let x = { &arr[0] };
|
LL | let x = { &arr[0] };
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let x = { arr[0].clone() };
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[String; 2]`, a non-copy array
|
error[E0508]: cannot move out of type `[String; 2]`, a non-copy array
|
||||||
--> $DIR/cannot-move-block-spans.rs:12:22
|
--> $DIR/cannot-move-block-spans.rs:12:22
|
||||||
|
@ -61,6 +80,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let y = unsafe { &arr[0] };
|
LL | let y = unsafe { &arr[0] };
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let y = unsafe { arr[0].clone() };
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error[E0508]: cannot move out of type `[String; 2]`, a non-copy array
|
error[E0508]: cannot move out of type `[String; 2]`, a non-copy array
|
||||||
--> $DIR/cannot-move-block-spans.rs:13:26
|
--> $DIR/cannot-move-block-spans.rs:13:26
|
||||||
|
@ -75,6 +98,10 @@ help: consider borrowing here
|
||||||
|
|
|
|
||||||
LL | let z = loop { break &arr[0]; };
|
LL | let z = loop { break &arr[0]; };
|
||||||
| +
|
| +
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL | let z = loop { break arr[0].clone(); };
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
||||||
--> $DIR/cannot-move-block-spans.rs:17:38
|
--> $DIR/cannot-move-block-spans.rs:17:38
|
||||||
|
@ -87,6 +114,11 @@ help: consider removing the dereference here
|
||||||
LL - let x = { let mut u = 0; u += 1; *r };
|
LL - let x = { let mut u = 0; u += 1; *r };
|
||||||
LL + let x = { let mut u = 0; u += 1; r };
|
LL + let x = { let mut u = 0; u += 1; r };
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let x = { let mut u = 0; u += 1; *r };
|
||||||
|
LL + let x = { let mut u = 0; u += 1; r.clone() };
|
||||||
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
||||||
--> $DIR/cannot-move-block-spans.rs:18:45
|
--> $DIR/cannot-move-block-spans.rs:18:45
|
||||||
|
@ -99,6 +131,11 @@ help: consider removing the dereference here
|
||||||
LL - let y = unsafe { let mut u = 0; u += 1; *r };
|
LL - let y = unsafe { let mut u = 0; u += 1; *r };
|
||||||
LL + let y = unsafe { let mut u = 0; u += 1; r };
|
LL + let y = unsafe { let mut u = 0; u += 1; r };
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let y = unsafe { let mut u = 0; u += 1; *r };
|
||||||
|
LL + let y = unsafe { let mut u = 0; u += 1; r.clone() };
|
||||||
|
|
|
||||||
|
|
||||||
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
error[E0507]: cannot move out of `*r` which is behind a shared reference
|
||||||
--> $DIR/cannot-move-block-spans.rs:19:49
|
--> $DIR/cannot-move-block-spans.rs:19:49
|
||||||
|
@ -111,6 +148,11 @@ help: consider removing the dereference here
|
||||||
LL - let z = loop { let mut u = 0; u += 1; break *r; u += 2; };
|
LL - let z = loop { let mut u = 0; u += 1; break *r; u += 2; };
|
||||||
LL + let z = loop { let mut u = 0; u += 1; break r; u += 2; };
|
LL + let z = loop { let mut u = 0; u += 1; break r; u += 2; };
|
||||||
|
|
|
|
||||||
|
help: consider cloning the value if the performance cost is acceptable
|
||||||
|
|
|
||||||
|
LL - let z = loop { let mut u = 0; u += 1; break *r; u += 2; };
|
||||||
|
LL + let z = loop { let mut u = 0; u += 1; break r.clone(); u += 2; };
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 9 previous errors
|
error: aborting due to 9 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue