Skip to content

Replace builtin # with k# - #162232

Merged
rust-bors[bot] merged 7 commits into
rust-lang:mainfrom
fmease:yeet-builtin-hash
Nov 4, 2026
Merged

rust-bors[bot] merged 7 commits into
rust-lang:mainfrom
fmease:yeet-builtin-hash

Conversation

@fmease

@fmease fmease commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

View all comments

Part of #153839. Also renames internal feature builtin_syntax to internal_syntax (without tombstoning) and keeps/reuses tracking issue #110680 (whose contents are going to get updated post merge).

Blocked on #161775 getting picked up by stage0 rustfmt (happened in PR #163483).

(No LLM was or will be used by me during the entire creation process of this PR)

@fmease fmease added S-blocked Status: Blocked on something else such as an RFC or other implementation work. rla-silenced Silences rust-log-analyzer postings to the PR it's added on. labels Sep 3, 2026
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Sep 3, 2026
@fmease fmease removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 3, 2026
Comment thread compiler/rustc_parse/src/parser/expr.rs Resolved
Comment thread compiler/rustc_span/src/symbol.rs Resolved
@fmease
fmease force-pushed the yeet-builtin-hash branch 2 times, most recently from 7415e73 to 1732079 Compare September 3, 2026 15:23
@rust-bors

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-bors

This comment has been minimized.

@fmease
fmease force-pushed the yeet-builtin-hash branch 3 times, most recently from 1e5e43a to 403ea1a Compare September 16, 2026 10:15
@rust-bors

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 28, 2026
Implement forced keywords (`k#`)



Part of #153839. CC @dianne

Introduces a new token kind to Rust >=2021 that looks like `k#ident` and that is called *forced keyword (identifier)*. This is gated behind a new unstable feature called `forced_keywords`. This is backed by [compiler MCP 945](rust-lang/compiler-team#945).

~~The `ident` in `k#ident` *must* be a keyword (from any edition) or a weak/contextual keyword for the token to be valid.~~ The `ident` in `k#ident` needn't be a keyword to be lexically valid (CC #161775 (comment)).

---

What **won't** be done in this PR:

1. implementing forced keyword lifetimes (`'k#static`)
2. migrating away from built-in syntax `builtin # $ident($($tt)*)` / introducing `k#`-exclusive (weak) keywords
   * that'll be done in PR #162232 instead
3. allowing the user to force edition-dependent & context-dependent keywords to be keywords
   * re. edition-dependent: forcing them to be keywords even in editions where they're usually not a (strong) keyword (today, that only affects `gen` anyway IINM)
   * re. context-dependent: E.g., `union` is only "active" if it's followed by a non-reserved identifier and under this PR the same rules apply to `k#union` even though that's not necessary; changing it would result in better diagnostics (e.g., for `k#union struct {}`: `` error: expected item, found `k#union` `` => `` expected identifier, found keyword `struct` ``) and maybe also allow for disambiguation for other context-dependent keywords
4. extending the `proc_macro::Ident` API to allow users to programmatically create forced keywords (might never be added)

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Sep 28, 2026
Implement forced keywords (`k#`)



Part of rust-lang/rust#153839. CC @dianne

Introduces a new token kind to Rust >=2021 that looks like `k#ident` and that is called *forced keyword (identifier)*. This is gated behind a new unstable feature called `forced_keywords`. This is backed by [compiler MCP 945](rust-lang/compiler-team#945).

~~The `ident` in `k#ident` *must* be a keyword (from any edition) or a weak/contextual keyword for the token to be valid.~~ The `ident` in `k#ident` needn't be a keyword to be lexically valid (CC rust-lang/rust#161775 (comment)).

---

What **won't** be done in this PR:

1. implementing forced keyword lifetimes (`'k#static`)
2. migrating away from built-in syntax `builtin # $ident($($tt)*)` / introducing `k#`-exclusive (weak) keywords
   * that'll be done in PR rust-lang/rust#162232 instead
3. allowing the user to force edition-dependent & context-dependent keywords to be keywords
   * re. edition-dependent: forcing them to be keywords even in editions where they're usually not a (strong) keyword (today, that only affects `gen` anyway IINM)
   * re. context-dependent: E.g., `union` is only "active" if it's followed by a non-reserved identifier and under this PR the same rules apply to `k#union` even though that's not necessary; changing it would result in better diagnostics (e.g., for `k#union struct {}`: `` error: expected item, found `k#union` `` => `` expected identifier, found keyword `struct` ``) and maybe also allow for disambiguation for other context-dependent keywords
4. extending the `proc_macro::Ident` API to allow users to programmatically create forced keywords (might never be added)

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 3, 2026
Replace `builtin #` with `k#`

Part of rust-lang#153839. Also renames internal feature `builtin_syntax` to `internal_syntax` (without tombstoning) and keeps/reuses tracking issue rust-lang#110680 (whose contents are going to get updated post merge).

~~Blocked on rust-lang#161775 getting picked up by stage0 rustfmt~~ (happened in PR rust-lang#163483).

<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
rust-bors Bot pushed a commit that referenced this pull request Nov 3, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #149245 (Make inline attributes apply to the generated `poll` in async fn)
 - #164304 ([perf] Reuse CanonicalVarKinds if no new variables were added)
 - #165109 (Avoid building a region map when erasing bound regions)
 - #163393 (std: Use getexecpath() for current_exe() on OpenBSD)
 - #165358 (Reenable some cg_gcc tests that were disabled)
 - #165371 (Don't use `llvm_type` as the type of `static`s.)
 - #162232 (Replace `builtin #` with `k#`)
 - #162608 (Avoid oscillating line wrapping due to symbol indices)
 - #164241 (make the safety documentation consistent in Ptr module)
 - #165029 (Use `MalformedLintAttributeInput` in more places)
 - #165203 (AIX: Implement TLS destructor guard in std and update dynamic-loading-cdylib test)
 - #165230 (Fix rigidity assertion ICE)
 - #165374 (Refactorings in preparation for the move trait)
rust-bors Bot pushed a commit that referenced this pull request Nov 3, 2026
This is failing when we combine:

1. Actually checking exit code for `dont_emit_ICE`, and
2. #162232 removing `builtin_syntax` `builtin #` (all
   editions) in favor of keyword prefixes `k#` as part of
   `forced_keywords`.

Cause is simple:

1. `dont_emit_ICE` checks exit code.
2. One of the listed tests, `tests/target/issue_6069.rs` was previously
   using `builtin #` syntax which is parsed on all editions, including
   default 2015 edition.
3. #162232 switched that test over to use `k#` reserved
   keyword syntax which is only Edition 2021+. Note the UI test actually
   get `//@ rustfmt-edition: 2021`.
4. `dont_emit_ICE` as an integration test does not set `--edition`
   explicitly, so Edition 2015 is used.
5. Now `issue_6069.rs` will not ICE but will fail to parse since it's on
   Edition 2015 not Edition 2021+.

To fix it, just run rustfmt with `--edition=2021` for `issue_6069.rs` in
`dont_emit_ICE` as well.

Relevant links:

- `builtin_syntax`: <#110694>
- MCP for switching to Edition 2021+ `k#` reserved keyword prefixes: <rust-lang/compiler-team#945>
- Tracking issue for `forced_keywords`: <#153839>
- Impl of `forced_keywords`: #161775
- Impl of MCP that also modified rustfmt tests to use `forced_keywords`: <#162232>.
@JonathanBrouwer

JonathanBrouwer commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

@bors r-
Soft-conflicts with #165378
Please rebase after that is merged

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 3, 2026
@rust-bors

rust-bors Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#165403), which was unapproved.

View changes since this unapproval

@jieyouxu

jieyouxu commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

@fmease sorry we need to get a rustfmt release for this cycle done, so doing the subtree sync first. Can you cherry-pick or squash or whatever the last test commit 5676e60 from #165409? Since we're now checking exit codes in dont_emit_ICE.

@ytmimi

ytmimi commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@jieyouxu I took a look at 5676e60, and the commit message says that issue_6069.rs is the failing tests, but then it applies "--edition=2021" to the issue-6105.rs test.

@jieyouxu

jieyouxu commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

@jieyouxu I took a look at 5676e60, and the commit message says that issue_6069.rs is the failing tests, but then it applies "--edition=2021" to the issue-6105.rs test.

🤦 I had two tabs open for dont_emit_ICE, one for this tree and one for rustfmt tree, I managed to copy pasta the wrong line 🤦 I meant src/tools/rustfmt/tests/target/issue_6159.rs (which is modified in this PR)... I just borked the commit message 🙈

EDIT: I force-pushed a commit 6da7b55 (same diff, just fixed the issue number in the commit msg cuz I can't read xD)

jieyouxu added a commit to jieyouxu/rust that referenced this pull request Nov 3, 2026
This is failing when we combine:

1. Actually checking exit code for `dont_emit_ICE`, and
2. rust-lang#162232 removing `builtin_syntax` `builtin #` (all
   editions) in favor of keyword prefixes `k#` as part of
   `forced_keywords`.

Cause is simple:

1. `dont_emit_ICE` checks exit code.
2. One of the listed tests, `tests/target/issue_6159.rs` was previously
   using `builtin #` syntax which is parsed on all editions, including
   default 2015 edition.
3. rust-lang#162232 switched that test over to use `k#` reserved
   keyword syntax which is only Edition 2021+. Note the UI test actually
   get `//@ rustfmt-edition: 2021`.
4. `dont_emit_ICE` as an integration test does not set `--edition`
   explicitly, so Edition 2015 is used.
5. Now `issue_6159.rs` will not ICE but will fail to parse since it's on
   Edition 2015 not Edition 2021+.

To fix it, just run rustfmt with `--edition=2021` for `issue_6159.rs` in
`dont_emit_ICE` as well.

Relevant links:

- `builtin_syntax`: <rust-lang#110694>
- MCP for switching to Edition 2021+ `k#` reserved keyword prefixes: <rust-lang/compiler-team#945>
- Tracking issue for `forced_keywords`: <rust-lang#153839>
- Impl of `forced_keywords`: rust-lang#161775
- Impl of MCP that also modified rustfmt tests to use `forced_keywords`: <rust-lang#162232>.
@ytmimi

ytmimi commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

It happens. Thank you for tracking down where this issue was and helping to get a fix for this PR :)

@fmease
fmease force-pushed the yeet-builtin-hash branch from 2a9fdf5 to fbd4136 Compare November 3, 2026 20:41
@rustbot

rustbot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

rustbot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtrees.

@fmease

fmease commented Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

I've cherry-picked jieyouxu's fix (6da7b55).

@bors r=JohnTitor force

@rust-bors

rust-bors Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit fbd4136 has been approved by JohnTitor

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 3, 2026
This is failing when we combine:

1. Actually checking exit code for `dont_emit_ICE`, and
2. rust-lang#162232 removing `builtin_syntax` `builtin #` (all
   editions) in favor of keyword prefixes `k#` as part of
   `forced_keywords`.

Cause is simple:

1. `dont_emit_ICE` checks exit code.
2. One of the listed tests, `tests/target/issue_6159.rs` was previously
   using `builtin #` syntax which is parsed on all editions, including
   default 2015 edition.
3. rust-lang#162232 switched that test over to use `k#` reserved
   keyword syntax which is only Edition 2021+. Note the UI test actually
   get `//@ rustfmt-edition: 2021`.
4. `dont_emit_ICE` as an integration test does not set `--edition`
   explicitly, so Edition 2015 is used.
5. Now `issue_6159.rs` will not ICE but will fail to parse since it's on
   Edition 2015 not Edition 2021+.

To fix it, just run rustfmt with `--edition=2021` for `issue_6159.rs` in
`dont_emit_ICE` as well.

Relevant links:

- `builtin_syntax`: <rust-lang#110694>
- MCP for switching to Edition 2021+ `k#` reserved keyword prefixes: <rust-lang/compiler-team#945>
- Tracking issue for `forced_keywords`: <rust-lang#153839>
- Impl of `forced_keywords`: rust-lang#161775
- Impl of MCP that also modified rustfmt tests to use `forced_keywords`: <rust-lang#162232>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants