Skip to content
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

Reassignment not considered by borrow rules #18185

Closed
tkoeppe opened this issue Oct 20, 2014 · 2 comments
Closed

Reassignment not considered by borrow rules #18185

tkoeppe opened this issue Oct 20, 2014 · 2 comments

Comments

@tkoeppe
Copy link

tkoeppe commented Oct 20, 2014

This may be a duplicate, but I haven't seen this resolved anywhere in the similar-looking issues. With the current nightly, the following borrow is not allowed:

let mut a = 2u;
let mut p = &mut a;
p = &mut a; // Error here: "a already borrowed"

In terms of lifetimes, the first borrow should end by the time p is being reassigned to. However, in the current version of Rust, the borrow is considered to be taken out as long as p is alive.

What is the current state of this, and are there plans to change the semantics of assignment to be able to end borrows?

@alexcrichton
Copy link
Member

I think this is a duplicate of #6393 which should allow the compiler to detect that the liveness of the original value of p is immediately dead after assignment (allowing a reassignment and a re-borrow of a).

@tkoeppe
Copy link
Author

tkoeppe commented Oct 20, 2014

That looks right, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants