-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Shorten drop scope of temporaries in conditions #111725
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
Shorten drop scope of temporaries in conditions #111725
Conversation
…emps(x) && DropTemps(y)"
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @davidtwco (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@cjgillot @dingxiangfei2009 does this address the concerns with the temporaries? thanks in advance. |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
Nominating this issue for lang team discussion. This PR makes 2 user-visible changes to the language:
Point 1 may create unexpected bugs for users that rely on drop order for synchronization (for instance). A crater run may be useful, but I'm not sure it will find such bugs. |
@@ -1,7 +1,7 @@ | |||
fn and_chain() { | |||
let z; | |||
if true && { z = 3; true} && z == 3 {} | |||
//~^ ERROR E0381 | |||
// no longer ERROR E0381 | |||
} | |||
|
|||
fn and_chain_2() { |
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.
Why is the test in this function unchanged?
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.
Sorry. I don't understand the question. It is changed. I removed the ~^
(meaning, it's no an error) and the output in tests/ui/rfc-2497-if-let-chains/chains-without-let.stderr
shows that.
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.
Or do you mean I need to merge master to resolve the conflict?
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 mean in the other function and_chain_2
.
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.
Because so far I'm only doing the &&
s inside the test of if
, not &&
as expression.
I agree that that too should be fixed, along with the ||
cases.
If this branch gets merged, I will fix the other cases.
Discussed in the rust-lang/lang meeting. We felt this change would require an edition. @dingxiangfei2009 and I are exploring some changes to temporary lifetimes for rust 2024 so perhaps you can reach out on Zulip and we can discuss there. |
During AST->HIR lowering, instead of transforming
to
now it gets transformed to
leading to subsequent passes (in MIR) to recognize the
&&
pattern inif e1 && e2
which was previously obscured by unneededUse
markers.Note that the
&&
itself never constructs temporaries and thus doesn't need to be wrapped byDropTemps
.Fixes #111583
Replaces #111644