You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Confusing error message with unimplemented Clone #55121
structTest(u64,u64);implTest{fninto_tuple(self) -> (u64,u64){(self.0,self.1)}}fnmain(){let x = vec![Test(1,1),Test(1,2)];let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();}
struct Test is not implementing Clone trait, but here is the error message:
Compiling playground v0.0.1 (file:///playground)
error[E0507]: cannot move out of borrowed content
--> src/main.rs:12:39
|
12 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^ cannot move out of borrowed content
error: aborting due to previous error
error[E0507]: cannot move out of borrowed content
--> src/main.rs:12:39
|
1 | struct Test(u64, u64);
| ---------------------- `Test` doesn't implement `Clone`
...
12 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^ cannot move out of borrowed content
|
= help: `test` is of type `&Test` and `Test` doesn't implement `Clone`, so you're cloning the borrow
error: aborting due to previous error
error[E0507]: cannot move out of a shared reference
--> src/main.rs:10:39
|
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^ move occurs because value has type `Test`, which does not implement the `Copy` trait
error[E0507]: cannot move out of a shared reference
--> src/main.rs:10:39
|
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^^------------
| | |
| | value moved due to this method call
| move occurs because value has type `Test`, which does not implement the `Copy` trait
|
note: `Test::into_tuple` takes ownership of the receiver `self`, which moves value
--> src/main.rs:3:19
|
3 | fn into_tuple(self) -> (u64, u64) {
| ^^^^
We should probably suggest #[derive(Copy)] on Test.
error[E0507]: cannot move out of a shared reference
--> f109.rs:10:39
|
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^ ------------ value moved due to this method call
| |
| move occurs because value has type `Test`, which does not implement the `Copy` trait
|
note: `Test::into_tuple` takes ownership of the receiver `self`, which moves value
--> f109.rs:3:19
|
3 | fn into_tuple(self) -> (u64, u64) {
| ^^^^
note: if `Test` implemented `Clone`, you could clone the value
--> f109.rs:1:1
|
1 | struct Test(u64, u64);
| ^^^^^^^^^^^
We could further explain that the .clone() is on the reference.
error[E0507]: cannot move out of a shared reference
--> src/main.rs:10:39
|
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^ ------------ value moved due to this method call
| |
| move occurs because value has type `Test`, which does not implement the `Copy` trait
|
note: `Test::into_tuple` takes ownership of the receiver `self`, which moves value
--> src/main.rs:3:19
|
3 | fn into_tuple(self) -> (u64, u64) {
| ^^^^
note: if `Test` implemented `Clone`, you could clone the value
--> src/main.rs:1:1
|
1 | struct Test(u64, u64);
| ^^^^^^^^^^^ consider implementing `Clone` for this type
...
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ------------ you could clone this value
Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of a shared reference
--> src/main.rs:10:39
|
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ^^^^^^^^^^^^ ------------ value moved due to this method call
| |
| move occurs because value has type `Test`, which does not implement the `Copy` trait
|
note: `Test::into_tuple` takes ownership of the receiver `self`, which moves value
--> src/main.rs:3:19
|
3 | fn into_tuple(self) -> (u64, u64) {
| ^^^^
note: if `Test` implemented `Clone`, you could clone the value
--> src/main.rs:1:1
|
1 | struct Test(u64, u64);
| ^^^^^^^^^^^ consider implementing `Clone` for this type
...
10 | let _tuples = x.iter().map(|test| test.clone().into_tuple()).collect::<Vec<_>>();
| ------------ you could clone this value
For more information about this error, try `rustc --explain E0507`.
Activity
estebank commentedon Oct 16, 2018
Proposed output:
estebank commentedon Jan 22, 2020
Triage, current output:
estebank commentedon Aug 3, 2023
Current output:
We should probably suggest
#[derive(Copy)]onTest.estebank commentedon Apr 12, 2024
Output with #122603:
We could further explain that the
.clone()is on the reference.estebank commentedon May 2, 2024
Current output:
andreytkachenko commentedon Oct 8, 2024
Now it produces better message: