Skip to content

Moving out of field error should emit resolution suggestions #64167

Open

Description

The current error doesn't help users resolve the problem. Even just including a message that one should try borrowing the field by prepending a & would be of help. I don't think it matters that this isn't possible for e.g. self.foo.consuming_method()

struct Foo {
    v: Vec<u32>,
}

impl Foo {
    fn bar(&self) {
        for _ in self.v {
            
        }
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of `self.v` which is behind a shared reference
 --> src/lib.rs:7:18
  |
7 |         for _ in self.v {
  |                  ^^^^^^ move occurs because `self.v` has type `std::vec::Vec<u32>`, which does not implement the `Copy` trait

error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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