Skip to content

nll suggestion about moving out of a &T is to make it a &mut T #55154

New issue

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

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

Already on GitHub? # to your account

Closed
oli-obk opened this issue Oct 17, 2018 · 1 comment
Closed

nll suggestion about moving out of a &T is to make it a &mut T #55154

oli-obk opened this issue Oct 17, 2018 · 1 comment
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Oct 17, 2018

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 (/playground)
error[E0507]: cannot move out of borrowed content
  --> src/main.rs:14:5
   |
14 |     sheep.talk();
   |     ^^^^^ cannot move out of borrowed content

error[E0507]: cannot move out of `*sheep` which is behind a `&` reference
  --> src/main.rs:14:5
   |
13 |     let sheep = &Sheep { message: "Määh".into() };
   |                 --------------------------------- help: consider changing this to be a mutable reference: `&mut Sheep { message: "Määh".into() }`
14 |     sheep.talk();
   |     ^^^^^
   |     |
   |     cannot move out of `*sheep` which is behind a `&` reference
   |     `sheep` is a `&` reference, so the data it refers to cannot be moved

error: aborting due to 2 previous errors

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 A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal labels Oct 17, 2018
@matthewjasper
Copy link
Contributor

cc #53004

@matthewjasper matthewjasper self-assigned this Oct 17, 2018
bors added a commit that referenced this issue Oct 22, 2018
…, r=pnkfelix

Don't emit cannot move errors twice in migrate mode

Closes #55154
cc #53004

r? @pnkfelix
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
…te-messages, r=pnkfelix

Don't emit cannot move errors twice in migrate mode

Closes rust-lang#55154
cc rust-lang#53004

r? @pnkfelix
bors added a commit that referenced this issue Oct 30, 2018
…, r=pnkfelix

Don't emit cannot move errors twice in migrate mode

Closes #55154
cc #53004

r? @pnkfelix
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal
Projects
None yet
Development

No branches or pull requests

2 participants