Skip to content

parens are not optional in guard chains that have || operators#2224

Merged
ehuss merged 2 commits into
rust-lang:masterfrom
tshepang:patch-2
May 26, 2026
Merged

parens are not optional in guard chains that have || operators#2224
ehuss merged 2 commits into
rust-lang:masterfrom
tshepang:patch-2

Conversation

@tshepang
Copy link
Copy Markdown
Member

No description provided.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Apr 11, 2026
Comment thread src/expressions/if-expr.md Outdated

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:
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 must be used. For example:
Copy link
Copy Markdown
Contributor

@ehuss ehuss Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is correct to use "must" here. This is saying that this is an option for how to work around the limitation. For example, you could sometimes use curly braces, or lift parts out to a variable, or don't use chains.

I think the correct change would be to move this statement out to an example block like the other one, since it isn't a language rule.

View changes since the review

Also
- Make an example follow convention (mark with `[!EXAMPLE]`)
- Change formatting to place comment closer to its code
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.
Copy link
Copy Markdown
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehuss ehuss enabled auto-merge May 26, 2026 19:36
@ehuss ehuss added this pull request to the merge queue May 26, 2026
Merged via the queue into rust-lang:master with commit eac7589 May 26, 2026
6 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants