Suggest .clone() in some move errors

```
error[E0507]: cannot move out of `*x` which is behind a shared reference
  --> $DIR/borrowck-fn-in-const-a.rs:6:16
   |
LL |         return *x
   |                ^^ move occurs because `*x` has type `String`, which does not implement the `Copy` trait
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL -         return *x
LL +         return x.clone()
   |
```
This commit is contained in:
Esteban Küber 2024-03-13 03:41:41 +00:00
parent bce78102c3
commit 10c2fbec24
35 changed files with 296 additions and 29 deletions

View File

@ -474,6 +474,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Some(desc) => format!("`{desc}`"),
None => "value".to_string(),
};
if let Some(expr) = self.find_expr(span) {
self.suggest_cloning(err, place_ty, expr, span);
}
err.subdiagnostic(
self.dcx(),
crate::session_diagnostics::TypeNoCopy::Label {
@ -582,6 +587,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if binds_to.len() == 1 {
let place_desc = &format!("`{}`", self.local_names[*local].unwrap());
if let Some(expr) = self.find_expr(binding_span) {
self.suggest_cloning(err, bind_to.ty, expr, binding_span);
}
err.subdiagnostic(
self.dcx(),
crate::session_diagnostics::TypeNoCopy::Label {

View File

@ -3,6 +3,12 @@ error[E0507]: cannot move out of `*x` which is behind a shared reference
|
LL | return *x
| ^^ move occurs because `*x` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - return *x
LL + return x.clone()
|
error: aborting due to 1 previous error

View File

@ -7,6 +7,11 @@ LL | Box::new(|| x)
| -- ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
| |
| captured by this `Fn` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | Box::new(|| x.clone())
| ++++++++
error: aborting due to 1 previous error

View File

@ -2,6 +2,6 @@
use std::rc::Rc;
pub fn main() {
let _x = <Vec<i32> as Clone>::clone(&Rc::new(vec![1, 2])).into_iter();
let _x = <Vec<i32> as Clone>::clone(&Rc::new(vec![1, 2]).clone()).into_iter();
//~^ ERROR [E0507]
}

View File

@ -12,6 +12,10 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | let _x = <Vec<i32> as Clone>::clone(&Rc::new(vec![1, 2])).into_iter();
| ++++++++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
|
LL | let _x = Rc::new(vec![1, 2]).clone().into_iter();
| ++++++++
error: aborting due to 1 previous error

View File

@ -15,6 +15,11 @@ LL | let _s2 = T{a: 2, ..s0};
| |
| cannot move out of here
| move occurs because `s0.mv` has type `Box<isize>`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let _s2 = T{a: 2, ..s0}.clone();
| ++++++++
error: aborting due to 2 previous errors

View File

@ -7,5 +7,5 @@ impl Foo {
}
fn main() {
let foo = &Foo;
<Foo as Clone>::clone(&(*foo)).foo(); //~ ERROR cannot move out
<Foo as Clone>::clone(&foo.clone()).foo(); //~ ERROR cannot move out
}

View File

@ -15,6 +15,11 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | <Foo as Clone>::clone(&(*foo)).foo();
| +++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
|
LL - (*foo).foo();
LL + foo.clone().foo();
|
error: aborting due to 1 previous error

View File

@ -22,6 +22,11 @@ error[E0507]: cannot move out of static item `settings_dir`
|
LL | let settings_data = from_string(settings_dir);
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let settings_data = from_string(settings_dir.clone());
| ++++++++
error: aborting due to 3 previous errors

View File

@ -6,6 +6,11 @@ LL | let _ = S1(C[0]).clone();
| |
| cannot move out of here
| move occurs because value has type `S2`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let _ = S1(C[0].clone()).clone();
| ++++++++
error: aborting due to 1 previous error

View File

@ -3,24 +3,48 @@ error[E0507]: cannot move out of `*u.a` which is behind a shared reference
|
LL | *u.a
| ^^^^ move occurs because `*u.a` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - *u.a
LL + u.a.clone()
|
error[E0507]: cannot move out of `*u.b` which is behind a mutable reference
--> $DIR/move-from-union-field-issue-66500.rs:16:5
|
LL | *u.b
| ^^^^ move occurs because `*u.b` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - *u.b
LL + u.b.clone()
|
error[E0507]: cannot move out of `*u.c` which is behind a raw pointer
--> $DIR/move-from-union-field-issue-66500.rs:20:5
|
LL | *u.c
| ^^^^ move occurs because `*u.c` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - *u.c
LL + u.c.clone()
|
error[E0507]: cannot move out of `*u.d` which is behind a raw pointer
--> $DIR/move-from-union-field-issue-66500.rs:24:5
|
LL | *u.d
| ^^^^ move occurs because `*u.d` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - *u.d
LL + u.d.clone()
|
error: aborting due to 4 previous errors

View File

@ -9,7 +9,7 @@ fn call<F>(f: F) where F : Fn() {
fn main() {
let y = vec![format!("World")];
call(|| {
<Vec<String> as Clone>::clone(&y).into_iter();
<Vec<String> as Clone>::clone(&y.clone()).into_iter();
//~^ ERROR cannot move out of `y`, a captured variable in an `Fn` closure
});
}

View File

@ -16,6 +16,10 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | <Vec<String> as Clone>::clone(&y).into_iter();
| +++++++++++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
|
LL | y.clone().into_iter();
| ++++++++
error: aborting due to 1 previous error

View File

@ -8,6 +8,10 @@ LL | struct StructA(String);
|
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -19,6 +23,10 @@ LL | struct StructA(String);
|
= note: `#[derive(PartialEq)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -30,6 +38,10 @@ LL | struct StructA(String);
|
= note: `#[derive(PartialEq)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -41,6 +53,10 @@ LL | struct StructA(String);
|
= note: `#[derive(PartialOrd)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -52,6 +68,10 @@ LL | struct StructA(String);
|
= note: `#[derive(PartialOrd)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -63,6 +83,10 @@ LL | struct StructA(String);
|
= note: `#[derive(Ord)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -74,6 +98,10 @@ LL | struct StructA(String);
|
= note: `#[derive(Ord)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -85,6 +113,10 @@ LL | struct StructA(String);
|
= note: `#[derive(Hash)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
@ -96,78 +128,142 @@ LL | struct StructA(String);
|
= note: `#[derive(Clone)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
LL | struct StructA(String.clone());
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:28:9
|
LL | self.0
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | self.0.clone()
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:38:20
|
LL | let x = &{ self.0 };
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let x = &{ self.0.clone() };
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:45:12
|
LL | ({ self.0 }) == ({ other.0 })
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | ({ self.0.clone() }) == ({ other.0 })
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:45:28
|
LL | ({ self.0 }) == ({ other.0 })
| ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | ({ self.0 }) == ({ other.0.clone() })
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:53:36
|
LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 })
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | PartialOrd::partial_cmp(&{ self.0.clone() }, &{ other.0 })
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:53:49
|
LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 })
| ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0.clone() })
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:68:20
|
LL | let x = &{ self.0 };
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let x = &{ self.0.clone() };
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:75:12
|
LL | ({ self.0 }) == ({ other.0 })
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | ({ self.0.clone() }) == ({ other.0 })
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:75:28
|
LL | ({ self.0 }) == ({ other.0 })
| ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | ({ self.0 }) == ({ other.0.clone() })
| ++++++++
error[E0507]: cannot move out of `self` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:83:36
|
LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 })
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | PartialOrd::partial_cmp(&{ self.0.clone() }, &{ other.0 })
| ++++++++
error[E0507]: cannot move out of `other` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:83:49
|
LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 })
| ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0.clone() })
| ++++++++
error[E0507]: cannot move out of `arg` which is behind a shared reference
--> $DIR/deriving-with-repr-packed-move-errors.rs:92:5
|
LL | arg.0
| ^^^^^ move occurs because `arg.0` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | arg.0.clone()
| ++++++++
error: aborting due to 21 previous errors

View File

@ -6,6 +6,11 @@ LL | let _b = A { y: Arc::new(3), ..a };
| |
| cannot move out of here
| move occurs because `a.x` has type `Arc<isize>`, which does not implement the `Copy` trait
|
help: clone the value to increment its reference count
|
LL | let _b = A { y: Arc::new(3), ..a }.clone();
| ++++++++
error: aborting due to 1 previous error

View File

@ -3,6 +3,11 @@ error[E0507]: cannot move out of `self.tokens` which is behind a shared referenc
|
LL | self.tokens
| ^^^^^^^^^^^ move occurs because `self.tokens` has type `Vec<isize>`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | self.tokens.clone()
| ++++++++
error: aborting due to 1 previous error

View File

@ -3,6 +3,12 @@ error[E0507]: cannot move out of `*key` which is behind a shared reference
|
LL | String::from_utf8(*key).unwrap()
| ^^^^ move occurs because `*key` has type `Vec<u8>`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - String::from_utf8(*key).unwrap()
LL + String::from_utf8(key.clone()).unwrap()
|
error: aborting due to 1 previous error

View File

@ -7,6 +7,11 @@ LL | let _f = to_fn(|| test(i));
| -- ^ move occurs because `i` has type `Box<usize>`, which does not implement the `Copy` trait
| |
| captured by this `Fn` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let _f = to_fn(|| test(i.clone()));
| ++++++++
error: aborting due to 1 previous error

View File

@ -1,18 +0,0 @@
//@ run-rustfix
#![allow(dead_code, noop_method_call)]
use std::ops::Deref;
struct S(Vec<usize>);
impl Deref for S {
type Target = Vec<usize>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl S {
fn foo(&self) {
// `self.clone()` returns `&S`, not `Vec`
for _ in <Vec<usize> as Clone>::clone(&self).into_iter() {} //~ ERROR cannot move out of dereference of `S`
}
}
fn main() {}

View File

@ -1,4 +1,3 @@
//@ run-rustfix
#![allow(dead_code, noop_method_call)]
use std::ops::Deref;
struct S(Vec<usize>);

View File

@ -1,5 +1,5 @@
error[E0507]: cannot move out of dereference of `S`
--> $DIR/needs-clone-through-deref.rs:15:18
--> $DIR/needs-clone-through-deref.rs:14:18
|
LL | for _ in self.clone().into_iter() {}
| ^^^^^^^^^^^^ ----------- value moved due to this method call
@ -12,6 +12,10 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | for _ in <Vec<usize> as Clone>::clone(&self).into_iter() {}
| ++++++++++++++++++++++++++++++ ~
help: consider cloning the value if the performance cost is acceptable
|
LL | for _ in self.clone().clone().into_iter() {}
| ++++++++
error: aborting due to 1 previous error

View File

@ -7,5 +7,5 @@ impl Foo {
}
fn main() {
let foo = &Foo;
<Foo as Clone>::clone(&foo).foo(); //~ ERROR cannot move out
<Foo as Clone>::clone(&foo.clone()).foo(); //~ ERROR cannot move out
}

View File

@ -15,6 +15,10 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | <Foo as Clone>::clone(&foo).foo();
| +++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
|
LL | foo.clone().foo();
| ++++++++
error: aborting due to 1 previous error

View File

@ -3,12 +3,22 @@ error[E0507]: cannot move out of an `Rc`
|
LL | drop(x.field);
| ^^^^^^^ move occurs because value has type `Vec<i32>`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | drop(x.field.clone());
| ++++++++
error[E0507]: cannot move out of an `Arc`
--> $DIR/issue-52086.rs:12:10
|
LL | drop(y.field);
| ^^^^^^^ move occurs because value has type `Vec<i32>`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | drop(y.field.clone());
| ++++++++
error: aborting due to 2 previous errors

View File

@ -7,6 +7,11 @@ LL | expect_fn(|| drop(x.0));
| -- ^^^ move occurs because `x.0` has type `Vec<i32>`, which does not implement the `Copy` trait
| |
| captured by this `Fn` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | expect_fn(|| drop(x.0.clone()));
| ++++++++
error: aborting due to 1 previous error

View File

@ -5,6 +5,10 @@ LL | VecWrapper::A(v) if { drop(v); false } => 1,
| ^ move occurs because `v` has type `Vec<i32>`, which does not implement the `Copy` trait
|
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
help: consider cloning the value if the performance cost is acceptable
|
LL | VecWrapper::A(v) if { drop(v.clone()); false } => 1,
| ++++++++
error[E0507]: cannot move out of `v` in pattern guard
--> $DIR/rfc-reject-double-move-across-arms.rs:15:51
@ -13,6 +17,10 @@ LL | VecWrapper::A(v) if let Some(()) = { drop(v); None } => 1,
| ^ move occurs because `v` has type `Vec<i32>`, which does not implement the `Copy` trait
|
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
help: consider cloning the value if the performance cost is acceptable
|
LL | VecWrapper::A(v) if let Some(()) = { drop(v.clone()); None } => 1,
| ++++++++
error: aborting due to 2 previous errors

View File

@ -5,6 +5,10 @@ LL | A { a: v } if { drop(v); true } => v,
| ^ move occurs because `v` has type `Box<i32>`, which does not implement the `Copy` trait
|
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
help: consider cloning the value if the performance cost is acceptable
|
LL | A { a: v } if { drop(v.clone()); true } => v,
| ++++++++
error[E0507]: cannot move out of `v` in pattern guard
--> $DIR/rfc-reject-double-move-in-first-arm.rs:17:45
@ -13,6 +17,10 @@ LL | A { a: v } if let Some(()) = { drop(v); Some(()) } => v,
| ^ move occurs because `v` has type `Box<i32>`, which does not implement the `Copy` trait
|
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
help: consider cloning the value if the performance cost is acceptable
|
LL | A { a: v } if let Some(()) = { drop(v.clone()); Some(()) } => v,
| ++++++++
error: aborting due to 2 previous errors

View File

@ -43,6 +43,11 @@ LL | f(Box::new(|a| {
LL |
LL | foo(f);
| ^ move occurs because `f` has type `{closure@$DIR/borrowck-call-is-borrow-issue-12224.rs:52:17: 52:58}`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | foo(f.clone());
| ++++++++
error[E0505]: cannot move out of `f` because it is borrowed
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:55:16

View File

@ -8,9 +8,9 @@ struct Foo {
impl Foo {
fn bar(&self) {
for _ in &self.v { //~ ERROR cannot move out of `self.v` which is behind a shared reference
for _ in &self.v.clone() { //~ ERROR cannot move out of `self.v` which is behind a shared reference
}
for _ in &self.h { //~ ERROR cannot move out of `self.h` which is behind a shared reference
for _ in &self.h.clone() { //~ ERROR cannot move out of `self.h` which is behind a shared reference
}
}
}
@ -18,7 +18,7 @@ impl Foo {
const LOADERS: &Vec<&'static u8> = &Vec::new();
pub fn break_code() -> Option<&'static u8> {
for loader in &*LOADERS { //~ ERROR cannot move out of a shared reference
for loader in &LOADERS.clone() { //~ ERROR cannot move out of a shared reference
return Some(loader);
}
None

View File

@ -13,6 +13,10 @@ help: consider iterating over a slice of the `Vec<u32>`'s content to avoid movin
|
LL | for _ in &self.v {
| +
help: consider cloning the value if the performance cost is acceptable
|
LL | for _ in self.v.clone() {
| ++++++++
error[E0507]: cannot move out of `self.h` which is behind a shared reference
--> $DIR/for-i-in-vec.rs:13:18
@ -27,6 +31,10 @@ help: consider iterating over a slice of the `HashMap<i32, i32>`'s content to av
|
LL | for _ in &self.h {
| +
help: consider cloning the value if the performance cost is acceptable
|
LL | for _ in self.h.clone() {
| ++++++++
error[E0507]: cannot move out of a shared reference
--> $DIR/for-i-in-vec.rs:21:19
@ -43,6 +51,11 @@ help: consider iterating over a slice of the `Vec<&u8>`'s content to avoid movin
|
LL | for loader in &*LOADERS {
| +
help: consider cloning the value if the performance cost is acceptable
|
LL - for loader in *LOADERS {
LL + for loader in LOADERS.clone() {
|
error: aborting due to 3 previous errors

View File

@ -7,7 +7,7 @@ impl LipogramCorpora {
pub fn validate_all(&mut self) -> Result<(), char> {
for selection in &self.selections {
if selection.1.is_some() {
if <Option<String> as Clone>::clone(&selection.1).unwrap().contains(selection.0) {
if <Option<String> as Clone>::clone(&selection.1.clone()).unwrap().contains(selection.0) {
//~^ ERROR cannot move out of `selection.1`
return Err(selection.0);
}
@ -25,7 +25,7 @@ impl LipogramCorpora2 {
pub fn validate_all(&mut self) -> Result<(), char> {
for selection in &self.selections {
if selection.1.is_ok() {
if <Result<String, String> as Clone>::clone(&selection.1).unwrap().contains(selection.0) {
if <Result<String, String> as Clone>::clone(&selection.1.clone()).unwrap().contains(selection.0) {
//~^ ERROR cannot move out of `selection.1`
return Err(selection.0);
}

View File

@ -13,6 +13,10 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | if <Option<String> as Clone>::clone(&selection.1).unwrap().contains(selection.0) {
| ++++++++++++++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
|
LL | if selection.1.clone().unwrap().contains(selection.0) {
| ++++++++
error[E0507]: cannot move out of `selection.1` which is behind a shared reference
--> $DIR/option-content-move.rs:28:20
@ -29,6 +33,10 @@ help: you can `clone` the value and consume it, but this might not be your desir
|
LL | if <Result<String, String> as Clone>::clone(&selection.1).unwrap().contains(selection.0) {
| ++++++++++++++++++++++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
|
LL | if selection.1.clone().unwrap().contains(selection.0) {
| ++++++++
error: aborting due to 2 previous errors

View File

@ -3,6 +3,12 @@ error[E0507]: cannot move out of `*t` which is behind a shared reference
|
LL | *t
| ^^ move occurs because `*t` has type `String`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL - *t
LL + t.clone()
|
error: aborting due to 1 previous error

View File

@ -7,6 +7,11 @@ LL | let f = to_fn(|| drop(x));
| -- ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
| |
| captured by this `Fn` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let f = to_fn(|| drop(x.clone()));
| ++++++++
error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
--> $DIR/unboxed-closure-illegal-move.rs:19:35
@ -17,6 +22,11 @@ LL | let f = to_fn_mut(|| drop(x));
| -- ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
| |
| captured by this `FnMut` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let f = to_fn_mut(|| drop(x.clone()));
| ++++++++
error[E0507]: cannot move out of `x`, a captured variable in an `Fn` closure
--> $DIR/unboxed-closure-illegal-move.rs:28:36
@ -27,6 +37,11 @@ LL | let f = to_fn(move || drop(x));
| ------- ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
| |
| captured by this `Fn` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let f = to_fn(move || drop(x.clone()));
| ++++++++
error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
--> $DIR/unboxed-closure-illegal-move.rs:32:40
@ -37,6 +52,11 @@ LL | let f = to_fn_mut(move || drop(x));
| ------- ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
| |
| captured by this `FnMut` closure
|
help: consider cloning the value if the performance cost is acceptable
|
LL | let f = to_fn_mut(move || drop(x.clone()));
| ++++++++
error: aborting due to 4 previous errors

View File

@ -44,6 +44,11 @@ LL | move_out(x.f1_nocopy);
| |
| cannot move out of here
| move occurs because `x.f1_nocopy` has type `ManuallyDrop<RefCell<i32>>`, which does not implement the `Copy` trait
|
help: consider cloning the value if the performance cost is acceptable
|
LL | move_out(x.f1_nocopy.clone());
| ++++++++
error: aborting due to 3 previous errors