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
@tshepang tshepang deleted the patch-2 branch May 30, 2026 19:40
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 2, 2026
Update books

## rust-lang/reference

10 commits in ad35aca481751a06afeb23820a672b0f3b11a476..01b0ee707f4571e803c8b2c471d8335a448f5d60
2026-05-31 18:52:24 UTC to 2026-05-20 14:06:08 UTC

- Update `naked` to use the attribute template (rust-lang/reference#1908)
- Update link_name for updated restrictions (rust-lang/reference#2268)
- parens are not optional in guard chains that have || operators (rust-lang/reference#2224)
- Document `target_has_atomic_primitive_alignment` (rust-lang/reference#2273)
- Fix grammar rules pertaining to obsolete range patterns (rust-lang/reference#2259)
- Unwrap a few remaining chapters (rust-lang/reference#2276)
- Guarantee alignment of `repr(C)` structs with no fields (rust-lang/reference#2264)
- avoid using 'place projection' for only some of the projections (rust-lang/reference#2253)
- add xtask doctest (rust-lang/reference#2255)
- Grammar: Don't allow inner attrs in certain block expressions (rust-lang/reference#2269)

## rust-lang/rust-by-example

7 commits in 898f0ac1479223d332309e0fce88d44b39927d28..d3117f6c873acbbf331c1d510371d061dfcc975c
2026-06-01 14:19:19 UTC to 2026-05-25 13:19:23 UTC

- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2018)
- Match comment module & file order (rust-lang/rust-by-example#2009)
- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2011)
- Update expression.md: renamed variable x_cube to x_cubed (rust-lang/rust-by-example#2012)
- Update comment.md - Fixed comments related to asterisk column (rust-lang/rust-by-example#2013)
- Minor typo in meta.md (rust-lang/rust-by-example#2016)
- Fix erroroneous implication (rust-lang/rust-by-example#2017)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 2, 2026
Update books

## rust-lang/reference

10 commits in ad35aca481751a06afeb23820a672b0f3b11a476..01b0ee707f4571e803c8b2c471d8335a448f5d60
2026-05-31 18:52:24 UTC to 2026-05-20 14:06:08 UTC

- Update `naked` to use the attribute template (rust-lang/reference#1908)
- Update link_name for updated restrictions (rust-lang/reference#2268)
- parens are not optional in guard chains that have || operators (rust-lang/reference#2224)
- Document `target_has_atomic_primitive_alignment` (rust-lang/reference#2273)
- Fix grammar rules pertaining to obsolete range patterns (rust-lang/reference#2259)
- Unwrap a few remaining chapters (rust-lang/reference#2276)
- Guarantee alignment of `repr(C)` structs with no fields (rust-lang/reference#2264)
- avoid using 'place projection' for only some of the projections (rust-lang/reference#2253)
- add xtask doctest (rust-lang/reference#2255)
- Grammar: Don't allow inner attrs in certain block expressions (rust-lang/reference#2269)

## rust-lang/rust-by-example

7 commits in 898f0ac1479223d332309e0fce88d44b39927d28..d3117f6c873acbbf331c1d510371d061dfcc975c
2026-06-01 14:19:19 UTC to 2026-05-25 13:19:23 UTC

- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2018)
- Match comment module & file order (rust-lang/rust-by-example#2009)
- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2011)
- Update expression.md: renamed variable x_cube to x_cubed (rust-lang/rust-by-example#2012)
- Update comment.md - Fixed comments related to asterisk column (rust-lang/rust-by-example#2013)
- Minor typo in meta.md (rust-lang/rust-by-example#2016)
- Fix erroroneous implication (rust-lang/rust-by-example#2017)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 2, 2026
Update books

## rust-lang/reference

10 commits in ad35aca481751a06afeb23820a672b0f3b11a476..01b0ee707f4571e803c8b2c471d8335a448f5d60
2026-05-31 18:52:24 UTC to 2026-05-20 14:06:08 UTC

- Update `naked` to use the attribute template (rust-lang/reference#1908)
- Update link_name for updated restrictions (rust-lang/reference#2268)
- parens are not optional in guard chains that have || operators (rust-lang/reference#2224)
- Document `target_has_atomic_primitive_alignment` (rust-lang/reference#2273)
- Fix grammar rules pertaining to obsolete range patterns (rust-lang/reference#2259)
- Unwrap a few remaining chapters (rust-lang/reference#2276)
- Guarantee alignment of `repr(C)` structs with no fields (rust-lang/reference#2264)
- avoid using 'place projection' for only some of the projections (rust-lang/reference#2253)
- add xtask doctest (rust-lang/reference#2255)
- Grammar: Don't allow inner attrs in certain block expressions (rust-lang/reference#2269)

## rust-lang/rust-by-example

7 commits in 898f0ac1479223d332309e0fce88d44b39927d28..d3117f6c873acbbf331c1d510371d061dfcc975c
2026-06-01 14:19:19 UTC to 2026-05-25 13:19:23 UTC

- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2018)
- Match comment module & file order (rust-lang/rust-by-example#2009)
- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2011)
- Update expression.md: renamed variable x_cube to x_cubed (rust-lang/rust-by-example#2012)
- Update comment.md - Fixed comments related to asterisk column (rust-lang/rust-by-example#2013)
- Minor typo in meta.md (rust-lang/rust-by-example#2016)
- Fix erroroneous implication (rust-lang/rust-by-example#2017)
rust-timer added a commit to rust-lang/rust that referenced this pull request Jun 2, 2026
Rollup merge of #157265 - rustbot:docs-update, r=ehuss

Update books

## rust-lang/reference

10 commits in ad35aca481751a06afeb23820a672b0f3b11a476..01b0ee707f4571e803c8b2c471d8335a448f5d60
2026-05-31 18:52:24 UTC to 2026-05-20 14:06:08 UTC

- Update `naked` to use the attribute template (rust-lang/reference#1908)
- Update link_name for updated restrictions (rust-lang/reference#2268)
- parens are not optional in guard chains that have || operators (rust-lang/reference#2224)
- Document `target_has_atomic_primitive_alignment` (rust-lang/reference#2273)
- Fix grammar rules pertaining to obsolete range patterns (rust-lang/reference#2259)
- Unwrap a few remaining chapters (rust-lang/reference#2276)
- Guarantee alignment of `repr(C)` structs with no fields (rust-lang/reference#2264)
- avoid using 'place projection' for only some of the projections (rust-lang/reference#2253)
- add xtask doctest (rust-lang/reference#2255)
- Grammar: Don't allow inner attrs in certain block expressions (rust-lang/reference#2269)

## rust-lang/rust-by-example

7 commits in 898f0ac1479223d332309e0fce88d44b39927d28..d3117f6c873acbbf331c1d510371d061dfcc975c
2026-06-01 14:19:19 UTC to 2026-05-25 13:19:23 UTC

- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2018)
- Match comment module & file order (rust-lang/rust-by-example#2009)
- Fix Spanish translation typos in es.po (rust-lang/rust-by-example#2011)
- Update expression.md: renamed variable x_cube to x_cubed (rust-lang/rust-by-example#2012)
- Update comment.md - Fixed comments related to asterisk column (rust-lang/rust-by-example#2013)
- Minor typo in meta.md (rust-lang/rust-by-example#2016)
- Fix erroroneous implication (rust-lang/rust-by-example#2017)
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