Skip to content

Commit eac7589

Browse files
authored
Merge pull request #2224 from tshepang/patch-2
parens are not optional in guard chains that have || operators
2 parents d0b0900 + d1fb175 commit eac7589

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/expressions/if-expr.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,20 @@ fn nested() {
186186
```
187187

188188
r[expr.if.chains.or]
189-
If any condition operand is a `let` pattern, then none of the condition operands can be a `||` [lazy boolean operator expression][expr.bool-logic] due to ambiguity and precedence with the `let` scrutinee. If a `||` expression is needed, then parentheses can be used. For example:
190-
191-
```rust
192-
# let foo = Some(123);
193-
# let condition1 = true;
194-
# let condition2 = false;
195-
// Parentheses are required here.
196-
if let Some(x) = foo && (condition1 || condition2) { /*...*/ }
197-
```
189+
If any condition operand is a `let` pattern, then none of the condition operands can be a `||` [lazy boolean operator expression][expr.bool-logic] due to ambiguity and precedence with the `let` scrutinee.
190+
191+
> [!EXAMPLE]
192+
> If a `||` expression is needed, then parentheses can be used. For example:
193+
>
194+
> ```rust
195+
> # let foo = Some(123);
196+
> # let condition1 = true;
197+
> # let condition2 = false;
198+
> if let Some(x) = foo
199+
> // Parentheses are required here.
200+
> && (condition1 || condition2)
201+
> {}
202+
> ```
198203
199204
r[expr.if.edition2024]
200205
> [!EDITION-2024]

src/expressions/match-expr.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ If any guard condition operand is a `let` pattern, then none of the condition op
240240
> ```rust
241241
> # let foo = Some([123]);
242242
> match foo {
243-
> // Parentheses are required here.
244-
> Some(xs) if let [x] = xs && (x < -100 || x > 20) => {}
243+
> Some(xs) if let [x] = xs
244+
> // Parentheses are required here.
245+
> && (x < -100 || x > 20) => {}
245246
> _ => {}
246247
> }
247248
> ```

0 commit comments

Comments
 (0)