You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: text/0000-let-else.md
+4-7
Original file line number
Diff line number
Diff line change
@@ -209,15 +209,13 @@ let (each, binding) = match expr {
209
209
```
210
210
211
211
Most expressions may be put into the expression position with two restrictions:
212
-
1. May not include a block outside of parenthesis.
213
-
- Must be an [`ExpressionWithoutBlock`][expressions].
214
-
-[`GroupedExpression`][grouped-expr]-s ending with a `}` are additionally not allowed and must be put in parenthesis.
212
+
1. May not end with a `}` (before macro expansion). (Such things must be put in parenthesis.)
215
213
2. May not be just a lazy boolean expression (`&&` or `||`). (Must not be a [`LazyBooleanExpression`][lazy-boolean-operators].)
216
214
217
215
While allowing e.g. `if {} else {}` directly in the expression position is technically feasible this RFC proposes it be
218
216
disallowed for programmer clarity so as to avoid `... else {} else {}` situations as discussed in the [drawbacks][] section.
219
217
Boolean matches are not useful with let-else and so lazy boolean expressions are disallowed for reasons noted in [future-possibilities][].
220
-
These types of expressions can still be used when combined in a less ambiguous manner with parenthesis, thus forming a [`GroupedExpression`][grouped-expr],
218
+
These types of expressions can still be used when combined in a less ambiguous manner with parenthesis,
221
219
which is allowed under the two expression restrictions.
222
220
223
221
Any refutable pattern that could be put into if-let's pattern position can be put into let-else's pattern position.
@@ -278,7 +276,7 @@ because the compiler won't interpret it as `let PATTERN = (if y { a }) else { b
278
276
This can be overcome by making a raw if-else in the expression position a compile error and instead requiring that parentheses are inserted to disambiguate:
279
277
`let PATTERN = (if { a } else { b }) else { c };`.
280
278
281
-
Rust already provides us with such a restriction, and so the expression can be restricted to be a [`ExpressionWithoutBlock`][expressions].
279
+
This restriction can be made by checking if the expression ends in `}` after parsing but _before_ macro expansion.
The expression can be any [`ExpressionWithoutBlock`][expressions], in order to prevent `else {} else {}` confusion, as noted in [drawbacks][#drawbacks].
305
+
The expression must not end with a `}`, in order to prevent `else {} else {}` (and similar) confusion, as noted in [drawbacks][#drawbacks].
308
306
309
307
The `else` must be followed by a block, as in `if {} else {}`. This else block must be diverging as the outer
310
308
context cannot be guaranteed to continue soundly without assignment, and no alternate assignment syntax is provided.
@@ -643,7 +641,6 @@ because it is confusing to read syntactically, and it is functionally similar to
0 commit comments