Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/expressions/if-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,20 @@ fn nested() {
```

r[expr.if.chains.or]
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:

```rust
# let foo = Some(123);
# let condition1 = true;
# let condition2 = false;
// Parentheses are required here.
if let Some(x) = foo && (condition1 || condition2) { /*...*/ }
```
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.

> [!EXAMPLE]
> If a `||` expression is needed, then parentheses must be used. For example:
>
> ```rust
> # let foo = Some(123);
> # let condition1 = true;
> # let condition2 = false;
> if let Some(x) = foo
> // Parentheses are required here.
> && (condition1 || condition2)
> {}
> ```

r[expr.if.edition2024]
> [!EDITION-2024]
Expand Down
5 changes: 3 additions & 2 deletions src/expressions/match-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ If any guard condition operand is a `let` pattern, then none of the condition op
> ```rust
> # let foo = Some([123]);
> match foo {
> // Parentheses are required here.
> Some(xs) if let [x] = xs && (x < -100 || x > 20) => {}
> Some(xs) if let [x] = xs
> // Parentheses are required here.
> && (x < -100 || x > 20) => {}
> _ => {}
> }
> ```
Expand Down
Loading