Skip to content

Improve error message when moving out of a &-reference #15457

Description

@nwin

It would be nice if the following error message

test.rs:7:9: 7:13 error: cannot move out of dereference of `&`-pointer
test.rs:7         self.option.map(|x| x)
                  ^~~~
error: aborting due to previous error

would give a hint why exactly something was moved in the following code

struct Type {
    option: Option<Vec<u8>>
}

impl Type {
    fn method(&self) -> Option<Vec<u8>> {
        self.option.map(|x| x)
    }
}

fn main() {
    let _ = Type { option: None }.method();
}

Ideally "map takes option by value" or something like that.

Activity

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

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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions