Skip to content

Confusing error message with unimplemented Clone #55121

Closed
@andreytkachenko

Description

@andreytkachenko

Consider this example:

struct Test(u64, u64);
impl Test {
    fn into_tuple(self) -> (u64, u64) {
        (self.0, self.1)
    }
}
fn main() {
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions