Grammar: Don't allow inner attrs in certain block expressions#2269
Merged
Conversation
fmease
commented
May 11, 2026
| Statements? | ||
| `}` | ||
|
|
||
| BlockExpressionNoInnerAttributes -> |
Member
Author
There was a problem hiding this comment.
Naming inspired by TypeNoBounds.
5389944 to
255b7aa
Compare
ehuss
approved these changes
May 20, 2026
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)
pull Bot
pushed a commit
to xtqqczze/rust-lang-miri
that referenced
this pull request
Jun 4, 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rustc doesn't syntactically permit inner attributes (1) in the consequent & alternate blocks of if-expressions, (2) in the alternate block of let-statements (let/else) and (3) in blocks matched by macro metavariables of type
block.Intuitively that makes sense since inner attributes generally target the "owner" of the surrounding block (e.g., the overarching function item or while-expression), neither "the block itself" nor the sequence of statements in said block (so
fn f(_: Undef) { #![cfg(false)] }=#[cfg(false)] fn f(_: Undef) {}andwhile undef { #![cfg(false)] }=#[cfg(false)] while undef {}) which would be very surprising for if-exprs and let/else stmts I feel like and straight up ill-defined in the MBE case.Concretely, it would mean that
if undef { /*…*/ } else if undef { /*…*/ } else { #![cfg(false)] }would be equivalent to#[cfg(false)] if …; similarly forlet self::undef = /*…*/ else { #![cfg(false)] };/#[cfg(false)] let …;.I'm not sure if that's the "official" reasoning, I've yet to find that out. As far as I can tell, inner attributes have been illegal in then/else blocks since version 1.0 at least1.
Fixes #2212.
Footnotes
However, back in version 1.0 inner attributes weren't permitted in most expressions with blocks like in
whileexpressions or "normal" block exprs either (but they were already allowed in the block of function items) which were all lifted at some point except for if-expressions, of course. ↩