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
<!-- TODO: The exception above isn't accurate, see https://github.com/rust-lang/reference/issues/569 -->
17
25
18
26
r[expr.if.intro]
19
-
The syntax of an `if` expression is a sequence of one or more condition operands separated by `&&`,
20
-
followed by a consequent block, any number of `else if` conditions and blocks, and an optional trailing `else` block.
27
+
An `if` expression is a conditional branch in program control. The syntax of an `if` expression is a condition followed by a consequent block, any number of `else if` conditions and blocks, and an optional trailing `else` block. The condition may be an expression or a let chain. A let chain is a sequence of operands separated by `&&`.
21
28
22
29
r[expr.if.condition]
23
30
Condition operands must be either an [_Expression_] with a [boolean type] or a conditional `let` match.
@@ -110,7 +117,7 @@ r[expr.if.chains.intro]
110
117
Multiple condition operands can be separated with `&&`.
111
118
112
119
r[expr.if.chains.order]
113
-
Similar to a`&&`[_LazyBooleanOperatorExpression_], each operand is evaluated from left-to-right until an operand evaluates as `false` or a `let` match fails,
120
+
Similar to an`&&`[_LazyBooleanOperatorExpression_], each operand is evaluated from left-to-right until an operand evaluates as `false` or a `let` match fails,
114
121
in which case the subsequent operands are not evaluated.
115
122
116
123
r[expr.if.chains.bindings]
@@ -148,7 +155,7 @@ fn nested() {
148
155
```
149
156
150
157
r[expr.if.chains.or]
151
-
If any condition operand is a `let`pattern, then none of the condition operands can be a`||`[lazy boolean operator expression][_LazyBooleanOperatorExpression_] due to ambiguity and precedence with the `let` scrutinee.
158
+
If any condition operand is a `let`expression, then none of the condition operands can be an`||`[_LazyBooleanOperatorExpression_] or any other binary [operators] with a lower [precedence] than `&&` due to ambiguity and precedence with the `let` scrutinee.
152
159
If a `||` expression is needed, then parentheses can be used. For example:
153
160
154
161
```rust
@@ -160,7 +167,8 @@ if let Some(x) = foo && (condition1 || condition2) { /*...*/ }
160
167
```
161
168
162
169
r[expr.if.edition2024]
163
-
> **Edition differences**: Before the 2024 edition, let chains are not supported and only a single _IfCondition_ is allowed in an `if` expression.
170
+
> [!EDITION-2024]
171
+
> Before the 2024 edition, let chains are not supported and only a single [_Scrutinee_][grammar-Scrutinee] is allowed as the conditional expression in an `if` expression.
0 commit comments