-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Implement stronger guarantees for mutable borrows #14739
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🤘 |
I would r+, but Travis CI is showing legit looking failures |
Though it's not obvious to me how they are related to this PR |
The travis failure is unrelated to this PR (it'll be fixed by a snapshot) |
It will be simpler to make some of the changes that I need to make to analyze_move_out if it uses a loop rather than recursion.
… &Rc<LoanPath> It doesn't actually need the Rc, and it reduces the net number of pointer manipulations.
Currently analyze_move_out_from checks all restrictions on all base paths of the move path, but it only needs to check restrictions from loans of the base paths, and can disregard restrictions from loans of extensions of those base paths.
Currently analyze_move_out_from ignores the BorrowKind of loans, but the same logic is useful when restricted to loans of specific borrow kinds.
Also rename MoveError to UseError and MoveOk / MoveWhileBorrowed to UseOk / UseWhileBorrowed.
Fix all violations in the Rust source tree of the stronger guarantee of a unique access path for mutable borrows as described in #12624.
Implement the stronger guarantees for mutable borrows from #12624. This removes the ability to read from a mutably borrowed path for the duration of the borrow, and enforces a unique access path for any mutable borrow, for both reads and writes. This makes mutable borrows work better with concurrent accesses from multiple threads, and it opens the door for allowing moves out of mutably borrowed values, as long as a new value is written before the mutable borrow ends. This also aligns Rust more closely with academic languages based on substructural types and separation logic. The most common situation triggering an error after this change is a call to a function mutably borrowing self with self.field as one of the arguments. The workaround is to bind self.field to a temporary, but the need for these temporaries will hopefully go away after #6268 is fixed. Another situation that triggers an error is using the head expression of a match in an arm that binds a variable with a mutable reference. The use of the head expression needs to be replaced with an expression that reconstructs it from match-bound variables. This fixes #12624. [breaking-change]
Move analyze_restrictions_on_use and check_if_path_is_moved so that all of the code related to assignments is in a contiguous block at the end of the file.
I had to rebase to account for some intervening lexer and parser changes. |
@bors: retry |
bors
added a commit
that referenced
this pull request
Jun 14, 2014
Implement the stronger guarantees for mutable borrows proposed in #12624.
pnkfelix
referenced
this pull request
Jun 18, 2014
thereof.) PR 14739 injected the new message that this removes from one test case: borrowck-vec-pattern-loan-from-mut.rs When reviewing the test case, I was not able to convince myself that the error message was a legitimate thing to start emitting. Niko did not see an obvious reason for it either, so I am going to remove it and wait for someone (maybe Cameron Zwarich) to explain to me why we should be emitting it.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jun 5, 2023
…r=Veykril Parse bare dyn types with leading lifetime TIL types may start with a lifetime identifier e.g. `type A = 'static + Trait;`. When parsing types, leading lifetime followed by a plus sign should be parsed as a bare dyn type rather than a generic lifetime argument or error type (which is what we produce today). Although it's no longer accepted since Rust 2021, it wouldn't hurt to support this obsolete syntax.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement the stronger guarantees for mutable borrows proposed in #12624.