-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat k#ident
keywords as valid tokens
#119351
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer |
This comment has been minimized.
This comment has been minimized.
compiler/rustc_ast/src/token.rs
Outdated
@@ -299,6 +299,10 @@ pub enum TokenKind { | |||
/// It's recommended to use `Token::(ident,uninterpolate,uninterpolated_span)` to | |||
/// treat regular and interpolated identifiers in the same way. | |||
Ident(Symbol, /* is_raw */ bool), | |||
|
|||
/// A `k#ident` keyword | |||
Keyword(Symbol), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual keywords are Ident, so it seems confusing for a "forced keyword" to be special here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd probably want to prevent that from happening, so should we feature gate this specific token?
Yes, I think we should feature gate k#
and stabilize it separately and only if some stable feature would make use of it.
compiler/rustc_ast/src/token.rs
Outdated
/// A `k#ident` keyword | ||
Keyword(Symbol), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be merged with Ident
, which, instead of /* is_raw */ bool
would need
enum IdentKind {
/// The usual identifiers (or, depending on the context, keywords): `v`, `union`, `await`, `loop`.
Default,
/// Raw identifiers: `r#just_an_ident`, `r#loop`.
Raw,
/// Forced keywords: `k#break`, `k#await`, `k#some_new_experimental_keyword`.
Keyword,
}
@@ -185,6 +185,18 @@ impl<'a> StringReader<'a> { | |||
self.sess.raw_identifier_spans.push(span); | |||
token::Ident(sym, true) | |||
} | |||
// Treat `k#ident` as a normal identifier token before 2021. | |||
rustc_lexer::TokenKind::KeywordIdent if !self.mk_sp(start, self.pos).edition().at_least_rust_2021() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not is a bit hard to see here, would something like this work?
rustc_lexer::TokenKind::KeywordIdent if !self.mk_sp(start, self.pos).edition().at_least_rust_2021() => { | |
rustc_lexer::TokenKind::KeywordIdent if self.mk_sp(start, self.pos).edition() < Edition2021 => { |
just converted |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #119384) made this pull request unmergeable. Please resolve the merge conflicts. |
The CI failure is due to #118861 |
The job Click to see the possible cause of the failure (guessed by this bot)
|
closed due to design concerns, there is an alternative - using |
@fee1-dead what are the design concerns? |
No energy to revive this PR, so closing |
We treat
k#ident
as a valid token, since it could be useful in implementing experimental features without introducing too much frontend changes (for example, with deref patterns). However, this PR as is would also make the following code compile:We'd probably want to prevent that from happening, so should we feature gate this specific token?