From 81c52e0da02758ed5396dcc164646bc39141bd3a Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Thu, 30 Apr 2026 15:42:45 +0200 Subject: [PATCH 1/2] separate a comment from a rule Also - Make an example follow convention (mark with `[!EXAMPLE]`) - Change formatting to place comment closer to its code --- src/expressions/if-expr.md | 23 ++++++++++++++--------- src/expressions/match-expr.md | 5 +++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/expressions/if-expr.md b/src/expressions/if-expr.md index 26b895dcf2..c9a526183d 100644 --- a/src/expressions/if-expr.md +++ b/src/expressions/if-expr.md @@ -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] diff --git a/src/expressions/match-expr.md b/src/expressions/match-expr.md index 946ae4c7b4..28d1e6351c 100644 --- a/src/expressions/match-expr.md +++ b/src/expressions/match-expr.md @@ -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) => {} > _ => {} > } > ``` From d1fb175e68072d131eefa9381da1adcd71e2d306 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 26 May 2026 12:36:16 -0700 Subject: [PATCH 2/2] Reword "must" to "can" This is to match the original wording and to match the wording in expr.match.guard.chains.or. Parentheses are not necessarily the only way to work around this limitation. For example, you could sometimes use curly braces, or lift parts out to a variable, or don't use chains. --- src/expressions/if-expr.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expressions/if-expr.md b/src/expressions/if-expr.md index c9a526183d..bf344bf114 100644 --- a/src/expressions/if-expr.md +++ b/src/expressions/if-expr.md @@ -189,7 +189,7 @@ 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. > [!EXAMPLE] -> If a `||` expression is needed, then parentheses must be used. For example: +> If a `||` expression is needed, then parentheses can be used. For example: > > ```rust > # let foo = Some(123);