Skip to content

Make "cannot move out of borrowed content" more beginner friendly #55153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oli-obk opened this issue Oct 17, 2018 · 3 comments
Closed

Make "cannot move out of borrowed content" more beginner friendly #55153

oli-obk opened this issue Oct 17, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Oct 17, 2018

The following code emits "cannot move out of borrowed content" without any hint about the reason whatsoever. I think we should add a "help" pointing to the self argument of talk and stating something along the lines of "because of consuming argument here". If it's in the same crate, maybe even suggest to change it to a reference.

struct Sheep {
    message: String
}

impl Sheep {
    fn talk(self) {
        println!("{}", self.message);
    }
}

fn main()
{
    let sheep = &Sheep { message: "Määh".into() };
    sheep.talk();
}

(Playground)

Errors:

   Compiling playground v0.0.1 (file:///playground)
error[E0507]: cannot move out of borrowed content
  --> src/main.rs:14:5
   |
14 |     sheep.talk();
   |     ^^^^^ cannot move out of borrowed content

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.

@oli-obk oli-obk added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 17, 2018
@csmoe
Copy link
Member

csmoe commented Oct 18, 2018

as I mentioned in zulip when talked about #53882, the borrowck should have something like borrower/mover(consumer), etc to help the users find out where the behaviors occurs:

struct Sheep {
    message: String
}

impl Sheep {
    fn talk(self) {
       ^^^^^^^^^ ... mover
        println!("{}", self.message);
    }
}

fn main()
{
    let sheep = &Sheep { message: "Määh".into() };
    sheep.talk();
    ^^^^^ ... moved by `Sheep::talk`
}

@matthewjasper matthewjasper added the NLL-diagnostics Working towards the "diagnostic parity" goal label Oct 21, 2018
@crlf0710 crlf0710 added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2020
@jryans
Copy link
Contributor

jryans commented Dec 12, 2020

@rustbot label D-newcomer-roadblock

@rustbot rustbot added the D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. label Dec 12, 2020
@ibraheemdev
Copy link
Member

Duplicate of #43161

@oli-obk oli-obk closed this as completed Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. NLL-diagnostics Working towards the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants