-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
2229: Fix issues with move closures and mutability #80092
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
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b421cd5
Restrict precision of captures with `capture_disjoint_fields` set
arora-aman 3488082
Compute mutability of closure captures
arora-aman 1373f98
Test cases for handling mutable references
arora-aman 0897db5
Test for restricting capture precision
arora-aman 604cbdc
Fix unused 'mut' warning for capture's root variable
arora-aman c748f32
Fix incorrect use mut diagnostics
arora-aman ffd5327
Add fixme for precise path diagnostics
arora-aman fadf03e
Fix typos
arora-aman 0f4bab2
Fixme for closure origin when reborrow is implemented
arora-aman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Compute mutability of closure captures
When `capture_disjoint_fields` is not enabled, checking if the root variable binding is mutable would suffice. However with the feature enabled, the captured place might be mutable because it dereferences a mutable reference. This PR computes the mutability of each capture after capture analysis in rustc_typeck. We store this in `ty::CapturedPlace` and then use `ty::CapturedPlace::mutability` in mir_build and borrow_check.
- Loading branch information
commit 34880825828260fad0a74621e4a13fe7da9a4a9d
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -661,11 +661,17 @@ pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureLis | |
| /// Part of `MinCaptureInformationMap`; List of `CapturePlace`s. | ||
| pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>; | ||
|
|
||
| /// A `Place` and the corresponding `CaptureInfo`. | ||
| /// A composite describing a `Place` that is captured by a closure. | ||
| #[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, TypeFoldable, HashStable)] | ||
| pub struct CapturedPlace<'tcx> { | ||
| /// The `Place` that is captured. | ||
|
||
| pub place: HirPlace<'tcx>, | ||
|
|
||
| /// `CaptureKind` and expression(s) that resulted in such capture of `place`. | ||
| pub info: CaptureInfo<'tcx>, | ||
|
|
||
| /// Represents if `place` can be mutated or not. | ||
| pub mutability: hir::Mutability, | ||
| } | ||
|
|
||
| pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String { | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how you're adding comments here btw 😍