Repository navigation
Replace builtin # with k# - #162232
Replace builtin # with k##162232
builtin # with k##162232Conversation
7415e73 to
1732079
Compare
This comment has been minimized.
This comment has been minimized.
1732079 to
c0e43c3
Compare
This comment has been minimized.
This comment has been minimized.
c0e43c3 to
0030cf6
Compare
This comment has been minimized.
This comment has been minimized.
1e5e43a to
403ea1a
Compare
This comment has been minimized.
This comment has been minimized.
403ea1a to
cb9cc26
Compare
This comment has been minimized.
This comment has been minimized.
cb9cc26 to
25f51e1
Compare
This comment has been minimized.
This comment has been minimized.
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>
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>
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>
…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)
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>.
|
This pull request was unapproved. This PR was contained in a rollup (#165403), which was unapproved. |
🤦 I had two tabs open for EDIT: I force-pushed a commit 6da7b55 (same diff, just fixed the issue number in the commit msg cuz I can't read xD) |
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>.
|
It happens. Thank you for tracking down where this issue was and helping to get a fix for this PR :) |
2a9fdf5 to
fbd4136
Compare
|
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. |
|
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>.
View all comments
Part of #153839. Also renames internal feature
builtin_syntaxtointernal_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)