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: src/expressions/if-expr.md
+5
Original file line number
Diff line number
Diff line change
@@ -107,10 +107,14 @@ if let E::X(n) | E::Y(n) = v {
107
107
r[expr.if.chains]
108
108
## Chains of conditions
109
109
110
+
r[expr.if.chains.intro]
110
111
Multiple condition operands can be separated with `&&`.
112
+
113
+
r[expr.if.chains.order]
111
114
Similar to a `&&`[_LazyBooleanOperatorExpression_], each operand is evaluated from left-to-right until an operand evaluates as `false` or a `let` match fails,
112
115
in which case the subsequent operands are not evaluated.
113
116
117
+
r[expr.if.chains.bindings]
114
118
The bindings of each pattern are put into scope to be available for the next condition operand and the consequent block.
115
119
116
120
The following is an example of chaining multiple expressions, mixing `let` bindings and boolean expressions, and with expressions able to reference pattern bindings from previous expressions:
@@ -144,6 +148,7 @@ fn nested() {
144
148
}
145
149
```
146
150
151
+
r[expr.if.chains.or]
147
152
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.
148
153
If a `||` expression is needed, then parentheses can be used. For example:
0 commit comments