-
Notifications
You must be signed in to change notification settings - Fork 13.7k
temporary lifetime extension for block tail expressions #146098
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
Draft
dianne
wants to merge
9
commits into
rust-lang:master
Choose a base branch
from
dianne:extending-blocks
base: master
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.
Draft
+562
−126
Conversation
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
Co-authored-by: Travis Cross <tc@traviscross.com>
They now use the enclosing temporary scope as their scope, regardless of which `ScopeData` was used to mark it.
Co-authored-by: Travis Cross <tc@traviscross.com>
This comment has been minimized.
This comment has been minimized.
78995b7
to
2e55e56
Compare
@rustbot label -stable-nominated I'm not intending to stable-nominate this, at least. Someone else can, but I don't expect it's needed or that it would be accepted. |
Error: Label stable-nominated can only be set by Rust team members Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
This comment has been minimized.
This comment has been minimized.
2e55e56
to
eafdca9
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
stable-nominated
Nominated for backporting to the compiler in the stable channel.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team
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.
For convenience of implementation and testing, I've based this on #145838 with #145342's commits cherry-picked in, plus some slight tweaks and additional tests (#145838 (comment)). The real change this PR makes is the final commit.
This implements the temporary lifetime extension semantics I suggested in #145838 (comment), with the goal of making temporary lifetimes and drop order more consistent between extending and non-extending blocks. As a side-effect, this fixes #145784 with hopefully milder regressions than #145838 (in exchange for having much broader surface area).
Roughly, this subjects extending borrows (and
super let
s) in block tails to extended scopes, using the same rules aslet
statement initializers. Under this PR,now extends the lifetime of
temp()
to outlive the block tail in Rust 2024 regardless of whether the block is an extending expression in alet
statement initializer (in which context it was already extended to outlive the block before this PR). The scoping rules for tails of extending blocks remain the same: extending subexpressions' temporary scopes are extended based on the source of the lifetime extension (e.g. to match the scope of a parentlet
statement's bindings). For blocks not extended by any other source, extending borrows in the tail expression now share a temporary scope with the result of the block. This can in turn extend nested blocks within blocks' tail expressions:Since this uses the same rules as
let
, it only applies to extending sub-expressions.I'm opening this as a draft for now to have a separate place to test and discuss it. Before it can be properly reviewed, I think it should have more tests, it should be optimized, it should have a Reference PR to cross-reference, and the commit history should be cleaned up.
@rustbot label +T-lang