-
Notifications
You must be signed in to change notification settings - Fork 523
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
Document let_chains
again
#1740
base: master
Are you sure you want to change the base?
Conversation
Some notes about temporaries and drop order: TC's tests added to rust-lang/rust: https://github.com/rust-lang/rust/pull/133605/files TC's more up-to-date example playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=0ce26b5398487e95672adbf389ad946b Niko's writeup: rust-lang/rust#132833 (comment) |
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.
Scopes
I think the rule in scopes.md
labeled names.scopes.pattern-bindings.if-let
needs to be updated. My rough understanding is that the scope of an if let
binding extends into the following _IfCondition_s and the consequent block.
Edition
At the bottom of if-expr.md
, can you add something like:
r[expr.if.edition2024]
> **Edition differences**: Before the 2024 edition, let chains are not supported and only a single _IfCondition_ is allowed in an `if` expression.
I think it makes sense to be at the end of the "Chains of conditions" section? Also just want to double-check the accuracy here.
Destructors and drop scopes
I'd like to see some updates to the destructors page to explain the drop scopes affected by this change. I'm uncertain exactly which changes to make, but I think roughly they are:
destructors.scope.desugaring
--if let
(now justif
) can't be directly converted to a match expression, so I don't know how to phrase that.destructors.scope.temporary.enclosing
--if let
should be rephrased somehow. Perhaps it could be phrased as justif
, and somewhere say that multiple _IfCondition_s are translated to the equivalent nestedif
with single conditions?- Or, somehow word it in a similar way to how lazy boolean expressions are worded?
destructors.scope.temporary.edition2024
-- I'm uncertain if this needs rewording?
src/expressions/if-expr.md
Outdated
> [_Expression_]<sub>_except struct expression_</sub>\ | ||
> | `let` [_Pattern_] `=` [_Scrutinee_] |
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.
The expression cannot be a lazy-boolean, correct?
(Scrutinee already says it doesn't allow struct. It's a little redundant to say that here, but maybe it helps with clarity?)
> [_Expression_]<sub>_except struct expression_</sub>\ | |
> | `let` [_Pattern_] `=` [_Scrutinee_] | |
> [_Expression_]<sub>_except struct expression or lazy boolean expression_</sub>\ | |
> | `let` [_Pattern_] `=` [_Scrutinee_]<sub>_except struct expression or lazy boolean expression_</sub> | |
> | |
> [^if-condition-2024]: Editions before 2024 only allow a single _IfCondition_. |
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.
The expression cannot be a lazy-boolean, correct?
yeah, no ||
is allowed here. Only &&
. see disallowed-positions.rs
src/expressions/if-expr.md
Outdated
An `if` expression is a conditional branch in program control. | ||
The syntax of an `if` expression is a condition operand, followed by a consequent block, any number of `else if` conditions and blocks, and an optional trailing `else` block. | ||
The syntax of an `if` expression is a sequence of one or more condition operands separated by `&&`, | ||
followed by a consequent block, any number of `else if` conditions and blocks, and an optional trailing `else` block. | ||
|
||
r[expr.if.condition-bool] |
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.
Suggesting to rename this, since the condition can now have let
in addition to boolean expressions.
r[expr.if.condition-bool] | |
r[expr.if.condition] |
src/expressions/if-expr.md
Outdated
> (`else` ( [_BlockExpression_] | _IfExpression_ ) )<sup>\?</sup> | ||
> | ||
> _IfConditions_ :\ | ||
> _IfCondition_ ( && _IfCondition_ )* |
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.
> _IfCondition_ ( && _IfCondition_ )* | |
> _IfCondition_ ( && _IfCondition_ )*[^if-condition-2024] |
Thanks for the review. Applied your suggestions and addressed the other review points as well.
When I read that sentence, I thought it's fine, because there is probably a way to express everything with nested match plus break from loops. But it's a bit underspecified, so I made it a little bit more explicit that it's not just a straightforward translation to I made the new sentence suggest the new meaning a bit more clearly, but it's also now stating a bit of a tautology.
I think it's fine. One could swap out the |
Mostly a reapply of #1179 which was reverted by #1251. The reapply is not trivial as in the meantime there has been #1561 which caused merge conflicts. Also add some modifiers.
Tracking issue: rust-lang/rust#53667
Stabilization report: rust-lang/rust#132833