-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[generator_interior] Be more precise with scopes of borrowed places #94309
Conversation
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #94350) made this pull request unmergeable. Please resolve the merge conflicts. |
compiler/rustc_typeck/src/check/generator_interior/drop_ranges/record_consumed_borrow.rs
Outdated
Show resolved
Hide resolved
☔ The latest upstream changes (presumably #94634) made this pull request unmergeable. Please resolve the merge conflicts. |
Co-authored-by: Eric Holk <[email protected]>
This is all almost certainly wrong
Also includes a lengthy comment arguing the correctness. Co-authored-by: Niko Matsakis <[email protected]>
The change makes sense to me and is well documented. Thanks! @bors r+ |
📌 Commit 2fcd542 has been approved by |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
Rollup of 10 pull requests Successful merges: - rust-lang#91133 (Improve `unsafe` diagnostic) - rust-lang#93222 (Make ErrorReported impossible to construct outside `rustc_errors`) - rust-lang#93745 (Stabilize ADX target feature) - rust-lang#94309 ([generator_interior] Be more precise with scopes of borrowed places) - rust-lang#94698 (Remove redundant code from copy-suggestions) - rust-lang#94731 (Suggest adding `{ .. }` around a const function call with arguments) - rust-lang#94960 (Fix many spelling mistakes) - rust-lang#94982 (Add deprecated_safe feature gate and attribute, cc rust-lang#94978) - rust-lang#94997 (debuginfo: Fix ICE when generating name for type that produces a layout error.) - rust-lang#95000 (Fixed wrong type name in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
[generator_interior] Be more precise with scopes of borrowed places Previously the generator interior type checking analysis would use the nearest temporary scope as the scope of a borrowed value. This ends up being overly broad for cases such as: ```rust fn status(_client_status: &Client) -> i16 { 200 } fn main() { let client = Client; let g = move || match status(&client) { _status => yield, }; assert_send(g); } ``` In this case, the borrow `&client` could be considered in scope for the entirety of the `match` expression, meaning it would be viewed as live across the `yield`, therefore making the generator not `Send`. In most cases, we want to use the enclosing expression as the scope for a borrowed value which will be less than or equal to the nearest temporary scope. This PR changes the analysis to use the enclosing expression as the scope for most borrows, with the exception of borrowed RValues which are true temporary values that should have the temporary scope. There's one further exception where borrows of a copy such as happens in autoref cases also should be ignored despite being RValues. Joint work with `@nikomatsakis` Fixes rust-lang#57017 r? `@tmandry`
Drop Tracking: Implement `fake_read` callback This PR updates drop tracking's use of `ExprUseVisitor` so that we treat `fake_read` events as borrows. Without doing this, we were not handling match expressions correctly, which showed up as a breakage in the `addassign-yield.rs` test. We did not previously notice this because we still had rather large temporary scopes that we held borrows for, which changed in rust-lang#94309. This PR also includes a variant of the `addassign-yield.rs` test case to make sure we continue to have correct behavior here with drop tracking. r? `@nikomatsakis`
Drop Tracking: Implement `fake_read` callback This PR updates drop tracking's use of `ExprUseVisitor` so that we treat `fake_read` events as borrows. Without doing this, we were not handling match expressions correctly, which showed up as a breakage in the `addassign-yield.rs` test. We did not previously notice this because we still had rather large temporary scopes that we held borrows for, which changed in rust-lang#94309. This PR also includes a variant of the `addassign-yield.rs` test case to make sure we continue to have correct behavior here with drop tracking. r? `@nikomatsakis`
Previously the generator interior type checking analysis would use the nearest temporary scope as the scope of a borrowed value. This ends up being overly broad for cases such as:
In this case, the borrow
&client
could be considered in scope for the entirety of thematch
expression, meaning it would be viewed as live across theyield
, therefore making the generator notSend
.In most cases, we want to use the enclosing expression as the scope for a borrowed value which will be less than or equal to the nearest temporary scope. This PR changes the analysis to use the enclosing expression as the scope for most borrows, with the exception of borrowed RValues which are true temporary values that should have the temporary scope. There's one further exception where borrows of a copy such as happens in autoref cases also should be ignored despite being RValues.
Joint work with @nikomatsakis
Fixes #57017
r? @tmandry