Repository navigation
Replace builtin # with k# - #162232
Replace builtin # with k##162232fmease wants to merge 6 commits into
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>
This comment was marked as outdated.
This comment was marked as outdated.
|
@rustbot reroll |
|
Sorry about the pings, y'all. Maybe we should abandon the convention of calling the |
This comment has been minimized.
This comment has been minimized.
26ab44f to
71ec952
Compare
This comment has been minimized.
This comment has been minimized.
218e623 to
d8dbe1e
Compare
| // FIXME(deref_patterns, internal_syntax, forced_keywords, clippy): | ||
| // This should render `k#deref(...)` but unfortunately Clippy uses `pat_to_string` | ||
| // for the suggestions of its lint `unnested_or_patterns`. Smh fix Clippy to not | ||
| // rely on AST pretty printing `deref!(…)` for `Deref` patterns and please don't | ||
| // think about adding a flag to AST pretty to control the output. |
There was a problem hiding this comment.
Sadly it turns out that Clippy relies on AST pretty for a structured diagnostic suggestion. Well, it's only lint unnested_or_patterns that relies on pat_to_string (since its inception). Clippy already features tests involving deref!(…).
I don't want to handle this right now, so I'm postponing it. I fear the proper solution would be for Clippy to maintain its own pattern printer.
This comment has been minimized.
This comment has been minimized.
d8dbe1e to
6b86875
Compare
Is that the best name? Lots of things are "internal", we even have a category of "internal features". This sounds more like "keyword syntax" to me. The code seems to also call it "forced keywords". So maybe |
Feature I consider the name "internal syntax" to be superior to "built-in syntax" because what even is "built-in syntax"? Every syntactic construct is "built-in". Sure, the token streams passed to macros may follow extra syntactic rules that are defined by the macro but that's at a slightly different level of abstraction. Indeed, we have the concept of "internal features" -- "internal syntax" is a subset thereof / marked as such. I don't see how that is somehow an argument against the name. It's meant to guard a common "run-off-the-mill" class of syntactic constructs that are meant to be internal to the language / standard library. They're an alternative / successor to a certain class of built-in macros. The only other internal syntaxes besides that are negative bounds |
Wait, what does |
|
Oh I see, it guards some particular cases of "keywords" that we never intend to stabilize, as listed in #110680. |
This comment has been minimized.
This comment has been minimized.
6b86875 to
77524bb
Compare
|
cc @rust-lang/rustfmt |
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)