-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Propagate temporary lifetime extension into if and match. #121346
Conversation
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.
Yesss!! Such an underrated improvement 🤩
Co-authored-by: Daniel Henry-Mantilla <[email protected]>
7783e73
to
f4caa83
Compare
Based on discussion in the @rust-lang/lang meeting today: @rfcbot merge |
Team member @joshtriplett 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. |
@rfcbot reviewed I thought at first there were backwards compatibility concerns here. But as I dug in, I realized that there isn't. Looking at this example that Mara gave: fn main() {
drop(if true {
..;
&temp(0) // used to error, but now gets lifetime extended
} else {
..;
&temp(1) // used to error, but now gets lifetime extended
});
} This winds up being a guaranteed error because, when we enter into an (Same for |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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. |
… r=compiler-errors Propagate temporary lifetime extension into if and match. This PR makes this work: ```rust let a = if true { ..; &temp() // used to error, but now gets lifetime extended } else { ..; &temp() // used to error, but now gets lifetime extended }; ``` and ```rust let a = match () { _ => { ..; &temp() // used to error, but now gets lifetime extended } }; ``` to make it consistent with: ```rust let a = { ..; &temp() // lifetime is extended }; ``` This is one small part of [the temporary lifetimes work](rust-lang/lang-team#253). This part is backwards compatible (so doesn't need be edition-gated), because all code affected by this change previously resulted in a hard error.
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b3bd705): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.28s -> 675.727s (0.07%) |
This looks to be the likely cause of a regression in temporary lifetime extension in constant initializers. |
Although looking at the actual change, it doesn't quite make sense how this would be responsible when the other expr kinds don't "cover" the temporary lifetime the way that's being seen in #126562. So I guess there must be a different location where const promotion is handled that also needs to be taught to peek through |
Only candidate I saw with a quick scan was: rust/compiler/rustc_hir_typeck/src/rvalue_scopes.rs Lines 26 to 52 in 55cac26
but that's looking at ET not E& and I'm really not sure on the exact relation between the two |
(see issue for further information; it looks like this may have gotten fingered incorrectly) |
This PR makes this work:
and
to make it consistent with:
This is one small part of the temporary lifetimes work.
This part is backwards compatible (so doesn't need be edition-gated), because all code affected by this change previously resulted in a hard error.