-
Notifications
You must be signed in to change notification settings - Fork 41
document if let guards #693
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
a9d2416
79c2910
695990c
9045712
d44f6c2
f2bef9f
eba5309
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4645,7 +4645,22 @@ Match Expressions | |||||
| OuterAttributeOrDoc* Pattern MatchArmGuard? | ||||||
|
|
||||||
| MatchArmGuard ::= | ||||||
| $$if$$ Operand | ||||||
| $$if$$ (Operand | MatchGuardChain) | ||||||
|
|
||||||
| MatchGuardChain ::= | ||||||
| MatchGuardCondition ($$&&$$ MatchGuardCondition)* | ||||||
|
kirtchev-adacore marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| MatchGuardCondition ::= | ||||||
| (MatchGuardExpression | OuterAttributeOrDoc* MatchGuardLetPattern) | ||||||
|
|
||||||
| MatchGuardLetPattern ::= | ||||||
| $$let$$ Pattern $$=$$ MatchGuardExpression | ||||||
|
|
||||||
| MatchGuardExpression ::= | ||||||
| Expression | ||||||
|
|
||||||
| :dp:`fls_UlxLrpyPlVmv` | ||||||
| A :dt:`match guard expression` is any expression in category :s:`Expression`, except :s:`LazyBooleanExpression`, :s:`RangeFromToExpression`, :s:`RangeFromExpression`, :s:`RangeInclusiveExpression`, :s:`AssignmentExpression`, and :s:`CompoundAssignmentExpression`. | ||||||
|
tshepang marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| .. rubric:: Legality Rules | ||||||
|
|
||||||
|
|
@@ -4715,6 +4730,15 @@ match the :t:`[subject expression]'s` :t:`type`. | |||||
| The :t:`value` of a :t:`match expression` is the :t:`value` of the :t:`operand` | ||||||
| of the selected :t:`match arm`. | ||||||
|
|
||||||
| :dp:`fls_DT4N2rr6wpvZ` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This paragraph should follow "6.18:8 A match arm guard ...". |
||||||
| A :dt:`match guard chain` is a set of conditions that should each evaluate to ``true`` in the case of :t:`[match guard expression]s` or have a positive match in the case of a :t:`[match guard let pattern]s` for the :t:`match arm` to be selected. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the way this rule is worded, it appears that a single positive match is sufficient to evaluate the guard to true. How about
Suggested change
|
||||||
|
|
||||||
| :dp:`fls_AAuyKfxLgJ43` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think FLS still needs an explicit guard-specific rule for when arm-pattern bindings become values. Today the shared pattern rules say by-value bindings move or copy during pattern matching ( Could we add the guard-specific rule from the Reference here (or in the shared pattern / guard text), and tie it back to the existing immutability rule for match-arm-guard bindings? That would also explain why mutation through those bindings is rejected while the guard runs. Support:
|
||||||
| A :dt:`match guard let pattern` is a construct that evaluates if a :t:`match guard expression` matches the specified :t:`pattern`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| :dp:`fls_uCDQMkWx5OMS` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this stabilization is still incomplete outside The new local rule says bindings introduced by a guard Upstream needed matching updates in Support:
|
||||||
| Each :t:`let binding` in a :t:`match guard let pattern` is in scope for the rest of the :t:`match arm guard` as well as the :t:`match arm body`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| .. rubric:: Dynamic Semantics | ||||||
|
|
||||||
| :dp:`fls_g551l8r8yh6d` | ||||||
|
|
@@ -4767,11 +4791,6 @@ The :t:`evaluation` of a :t:`match arm matcher` proceeds as follows: | |||||
| #. :dp:`fls_yk8l9zjh7i0d` | ||||||
| Otherwise the :t:`match arm matcher` fails. | ||||||
|
|
||||||
| :dp:`fls_sbtx1l6n2tp2` | ||||||
| The :t:`evaluation` of a :t:`match arm guard` evaluates its :t:`operand`. A | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this paragraph is actually useful. In fact, there Dynamic Semantics section should be updated to account for match guard let patterns.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought it was redundant since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree the Dynamic Semantics section needs an explicit update here, not just a revised success criterion. As written, Could we make those parts explicit in Dynamic Semantics, perhaps by replacing the removed Support:
|
||||||
| :t:`match arm guard` evaluates to ``true`` when its :t:`operand` evaluates to | ||||||
| ``true``, otherwise it evaluates to ``false``. | ||||||
|
|
||||||
| .. rubric:: Examples | ||||||
|
|
||||||
| .. code-block:: rust | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
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 wonder whether these new non-terminal should have "MatchArm" in their names, as opposed to just "Match".
View changes since the review