Skip to content

Commit 7637ef8

Browse files
committed
move back to TokenKind
1 parent a689847 commit 7637ef8

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

compiler/rustc_lexer/src/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ pub enum TokenKind {
104104
/// for emoji identifier recovery, as those are not meant to be ever accepted.
105105
InvalidPrefix,
106106

107+
/// Guarded string literal prefix: `#"` or `##`.
108+
///
109+
/// Used for reserving "guarded strings" (RFC 3598) in edition 2024.
110+
/// Split into the component tokens on older editions.
111+
GuardedStrPrefix,
112+
107113
/// Examples: `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
108114
/// suffix, but may be present here on string and float literals. Users of
109115
/// this type will need to check for and reject that case.
@@ -205,11 +211,6 @@ pub enum LiteralKind {
205211
ByteStr { terminated: bool },
206212
/// `c"abc"`, `c"abc`
207213
CStr { terminated: bool },
208-
/// Guarded string literal prefix: `#"` or `##`.
209-
///
210-
/// Used for reserving "guarded strings" (RFC 3598) in edition 2024.
211-
/// Split into the component tokens on older editions.
212-
GuardedStrPrefix,
213214
/// `r"abc"`, `r#"abc"#`, `r####"ab"###"c"####`, `r#"a`. `None` indicates
214215
/// an invalid literal.
215216
RawStr { n_hashes: Option<u8> },
@@ -422,8 +423,7 @@ impl Cursor<'_> {
422423
// Guarded string literal prefix: `#"` or `##`
423424
'#' if matches!(self.first(), '"' | '#') => {
424425
self.bump();
425-
let suffix_start = self.pos_within_token();
426-
TokenKind::Literal { kind: GuardedStrPrefix, suffix_start }
426+
TokenKind::GuardedStrPrefix
427427
}
428428

429429
// One-symbol tokens.

compiler/rustc_parse/src/lexer/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
252252
let prefix_span = self.mk_sp(start, lit_start);
253253
return (Token::new(self.ident(start), prefix_span), preceded_by_whitespace);
254254
}
255-
rustc_lexer::TokenKind::Literal {
256-
kind: rustc_lexer::LiteralKind::GuardedStrPrefix,
257-
..
258-
} => self.maybe_report_guarded_str(start, str_before),
255+
rustc_lexer::TokenKind::GuardedStrPrefix => self.maybe_report_guarded_str(start, str_before),
259256
rustc_lexer::TokenKind::Literal { kind, suffix_start } => {
260257
let suffix_start = start + BytePos(suffix_start);
261258
let (kind, symbol) = self.cook_lexer_literal(start, suffix_start, kind);
@@ -607,7 +604,6 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
607604
}
608605
(kind, self.symbol_from_to(start, end))
609606
}
610-
rustc_lexer::LiteralKind::GuardedStrPrefix => unreachable!(),
611607
}
612608
}
613609

src/librustdoc/html/highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,8 @@ impl<'src> Classifier<'src> {
844844
| LiteralKind::RawCStr { .. } => Class::String,
845845
// Number literals.
846846
LiteralKind::Float { .. } | LiteralKind::Int { .. } => Class::Number,
847-
LiteralKind::GuardedStrPrefix => return no_highlight(sink),
848847
},
848+
TokenKind::GuardedStrPrefix => return no_highlight(sink),
849849
TokenKind::Ident | TokenKind::RawIdent if lookahead == Some(TokenKind::Bang) => {
850850
self.in_macro = true;
851851
sink(Highlight::EnterSpan { class: Class::Macro(self.new_span(before, text)) });

src/tools/rust-analyzer/crates/parser/src/lexed_str.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ impl<'a> Converter<'a> {
188188

189189
rustc_lexer::TokenKind::RawIdent => IDENT,
190190

191-
rustc_lexer::TokenKind::Literal { kind: GuardedStrPrefix, .. } => ERROR,
191+
rustc_lexer::TokenKind::GuardedStrPrefix => {
192+
err = "Invalid string literal (reserved syntax)";
193+
ERROR
194+
},
192195

193196
rustc_lexer::TokenKind::Literal { kind, .. } => {
194197
self.extend_literal(token_text.len(), kind);

0 commit comments

Comments
 (0)