Repository navigation
put guards' fake reads in the failure block and only put necessary fake reads in the success block #163948
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
Open
dianne
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
dianne:binding-fake-reads
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+320
−38
Open
put guards' fake reads in the failure block and only put necessary fake reads in the success block #163948
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //! On a guard's success path, we only add fake-reads for fake borrows on prefixes of by-value | ||
| //! bindings' places, since at that point we only need to be able to create by-value bindings. | ||
| //! Consequently, guards that can't fail after a matched-on place has been modified may still | ||
| //! borrow-check successfully if no by-value bindings depended on that place to still be valid. See | ||
| //! `divergent-guard-binding-restrictiveness.rs` for cases where the presence of bindings causes a | ||
| //! borrow-checking failure. | ||
| //@ check-pass | ||
| #![allow(unused)] | ||
|
|
||
| fn main() { | ||
| let mut x: (Option<&Box<u64>>, u64) = (Some(&Box::new(7)), 0); | ||
| match x { | ||
| // By-ref bindings are created before evaluating the guard, so we don't need fake borrows | ||
| // to catch when they would be invalidated. As long as we don't use `b` after, it's ok. | ||
| (Some(ref b), c) if { x.0 = None; false } || return => {} | ||
| (Some(ref b), c) if false && ({ x.0 = None; false } || return) => {} | ||
|
|
||
| // The assignment doesn't invalidate borrows of the lifetime-extended temporary box. It's | ||
| // unchanged even when `x` is set to `None`, so it's fine to read from after. | ||
| (Some(&ref b), c) if { x.0 = None; false } || return => { **b; } | ||
| (Some(&ref b), c) if false && ({ x.0 = None; false } || return) => { **b; } | ||
|
|
||
| a => { a; } | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //! On a guard's success path, we add fake-reads for fake-borrows on prefixes of by-value bindings' | ||
| //! places, since at that point we need to be able to create by-value bindings. For cases where we | ||
| //! omit unnecessary fake reads on the success path, see `divergent-guard-binding-permissivenss.rs`. | ||
|
|
||
| fn main() { | ||
| let mut x: Option<&u64> = Some(&7); | ||
| match x { | ||
| // These guards can succeed but not fail after `x = None`. Since `x` is a prefix of the by- | ||
| // value binding `b`'s place, we can't bind `b` if we do that. | ||
| Some(&b) if { x = None; false } || return => {} | ||
| //~^ ERROR: cannot assign `x` in match guard | ||
| Some(&b) if false || ({ x = None; false } || return) => {} | ||
| //~^ ERROR: cannot assign `x` in match guard | ||
|
|
||
| // If there isn't a deref between the modified place and the bound place, this may be caught | ||
| // instead by the fake read on the `RefWithinGuard` borrow of the binding. | ||
| Some(b) if { x = None; false } || return => {} | ||
| //~^ ERROR: cannot assign to `x` because it is borrowed | ||
| Some(b) if false || ({ x = None; false } || return) => {} | ||
| //~^ ERROR: cannot assign to `x` because it is borrowed | ||
|
|
||
| // By-ref bindings are created before evaluating the guard, so we don't need fake borrows | ||
| // to catch when they would be invalidated. | ||
| Some(ref b) if { x = None; false } || return => { b; } | ||
| //~^ ERROR: cannot assign to `x` because it is borrowed | ||
| Some(ref b) if false || ({ x = None; false } || return) => { b; } | ||
| //~^ ERROR: cannot assign to `x` because it is borrowed | ||
|
|
||
| _ => {} | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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 am missing an example like
Does this pass?
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.
Are these disallowed in #161581?