Skip to content

[blocked on 1.101.0 becoming beta & rustfmt stage0] Replace builtin # with k# - #162232

Draft
fmease wants to merge 6 commits into
rust-lang:mainfrom
fmease:yeet-builtin-hash
Draft

fmease wants to merge 6 commits into
rust-lang:mainfrom
fmease:yeet-builtin-hash

Conversation

@fmease

@fmease fmease commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Part of #153839. Also renames internal feature builtin_syntax to internal_syntax (without tombstoning) and keeps/reuses tracking issue #110680.

Blocked on #161775 reaching beta and getting picked up by stage0 rustfmt.

(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 Outdated
Comment thread compiler/rustc_span/src/symbol.rs
@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>
@fmease fmease changed the title Replace builtin # with k# [blocked on 1.101.0 becoming beta & stage0 (for rustfmt)] Replace builtin # with k# Sep 28, 2026
@fmease fmease changed the title [blocked on 1.101.0 becoming beta & stage0 (for rustfmt)] Replace builtin # with k# [blocked on 1.101.0 becoming beta & rustfmt stage0] Replace builtin # with k# Sep 28, 2026
@rust-bors

rust-bors Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #163661) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) rla-silenced Silences rust-log-analyzer postings to the PR it's added on. S-blocked Status: Blocked on something else such as an RFC or other implementation work. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants