Skip to content

Improve message for rustc --explain E0507 #31270

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

Merged
merged 1 commit into from
Feb 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/librustc_borrowck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,33 @@ fn main() {
}
```

Moving out of a member of a mutably borrowed struct is fine if you put something
back. `mem::replace` can be used for that:

```
struct TheDarkKnight;

impl TheDarkKnight {
fn nothing_is_true(self) {}
}

struct Batcave {
knight: TheDarkKnight
}

fn main() {
use std::mem;

let mut cave = Batcave {
knight: TheDarkKnight
};
let borrowed = &mut cave;

borrowed.knight.nothing_is_true(); // E0507
mem::replace(&mut borrowed.knight, TheDarkKnight).nothing_is_true(); // ok!
}
```

You can find more information about borrowing in the rust-book:
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
"##,
Expand Down