RFC: Drop temporaries in tail expressions before local variables by m-ou-se · Pu...
source link: https://github.com/rust-lang/rfcs/pull/3606
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
RFC: Drop temporaries in tail expressions before local variables #3606
Conversation
This is one of the results of the temporary lifetimes effort by @nikomatsakis @dingxiangfei2009 and me.
Originally, we were working on a much larger RFC with several changes, but decided to not block small things on big things.
This part is quite small, but requires an edition change.
added T-lang Relevant to the language team, which will review and decide on the RFC. A-drop Proposals relating to the Drop trait or drop semantics A-ergonomics
I-lang-nominated Indicates that an issue has been nominated for prioritizing at the next lang team meeting. A-edition-2024 Area: The 2024 edition
labels
# Reference-level explanation |
||
For blocks/bodies/arms whose `{}` tokens come from Rust 2024 code, |
||
temporaries in the tail expression will be dropped *before* the locals of the block are dropped. |
iiuc does this imply these drop orders in the following compositions?
Code | Drop order? |
---|---|
|
Current situation
|
|
This RFC
|
|
'24 block in '21 function
|
|
'21 block in '24 function (???)
|
Member
Author
Correct!
I don't expect to see people mixing editions like that though ^^'. The point is that a block expanded from a macro will behave the way the macro author expected. The edition of whoever wrote the block is used.
An example of something great with this is that it makes |
Contributor
Looking at the resulting breakage from this change I would personally love to just land this change by default in all editions instead of only in >=2024, treating it as "clarifying previously underspecified language semantics" (unless we formally stated the existing rules somewhere). This kind of subtle inconsistency between editions is likely to cause some confusion. I am also very much happy to also only have this behavior in the new edition but would like to at least mention this as an alternative. |
Contributor
@rfcbot fcp merge After much exploration, we've decided to break apart the "temporary lifetimes" change into two smaller items. This one corrects the lifetimes in the tail expressions of blocks, a common source of surprising compiler errors. The other item ( Lang team, let's do this! |
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it.
labels
Contributor
I could be persuaded here, but I am reluctant to make changes in semantics without an edition, because it is difficult to know what code out there may be affected. |
Member
Seems very well scoped and motivated for an edition change. Thanks for the effort that went into design and boiling it down to a simple RFC such as this. @rfcbot reviewed |
# Reference-level explanation |
||
For blocks/bodies/arms whose `{}` tokens come from Rust 2024 code, |
Thanks for including exactly which tokens trigger this behaviour 👍
added final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised.
and removed proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period.
labels
Collaborator
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Member
I would like to formally register a concerning regarding the effect on unsafe code. The RFC says
However, for unsafe code implicitly relying on the current drop order, it's unclear to me whether that is possible. (AFAIK rfcbot support for t-lang-advisors has not been implemented so if someone on t-lang could tell the bot about this concern that would be great. :) |
Member
Author
@RalfJung Your concern was discussed in the lang triage meeting just now. Niko said that we can warn for this situation (and that that such patterns with pointers are error-prone regardless, so we probably want to warn for such patterns also without this change). The lang team consensus in the meeting was, given the expectation that this can be linted for, this doesn't have to be a blocking concern on the RFC. (But instead something to take into account before stabilization, when there is more data.) I will add it to the unresolved questions in the RFC. |
This seems like a great change, but I was interested in seeing if any real-world code is broken by this. Where can I find the crater run with this change applied to all editions? |
added finished-final-comment-period The final comment period is finished for this RFC. to-announce
and removed final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised.
labels
Collaborator
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
No one assigned
A-drop Proposals relating to the Drop trait or drop semantics A-edition-2024 Area: The 2024 edition A-ergonomics disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. I-lang-nominated Indicates that an issue has been nominated for prioritizing at the next lang team meeting. T-lang Relevant to the language team, which will review and decide on the RFC. to-announce
None yet
No milestone
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK