diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-19 14:48:48 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-19 18:01:43 +1100 |
| commit | df29f9b0c3a2277c2eb2de2e0bf4f4b3329dbd00 (patch) | |
| tree | 5fef030d9da150e4d52e9db766459eeabebfacca /compiler/rustc_lexer | |
| parent | 03ee4845197ce71aa5ee28cb937a3e863b18b42f (diff) | |
| download | rust-df29f9b0c3a2277c2eb2de2e0bf4f4b3329dbd00.tar.gz rust-df29f9b0c3a2277c2eb2de2e0bf4f4b3329dbd00.zip | |
Improve `fake_ident_or_unknown_prefix`.
- Rename it as `invalid_ident_or_prefix`, which matches the possible
outputs (`InvalidIdent` or `InvalidPrefix`).
- Use the local wrapper for `is_xid_continue`, for consistency.
- Make it clear what `\u{200d}` means.
Diffstat (limited to 'compiler/rustc_lexer')
| -rw-r--r-- | compiler/rustc_lexer/src/lib.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index f9f2a14dbd2..7f221098364 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -468,7 +468,7 @@ impl Cursor<'_> { Literal { kind, suffix_start } } // Identifier starting with an emoji. Only lexed for graceful error recovery. - c if !c.is_ascii() && c.is_emoji_char() => self.fake_ident_or_unknown_prefix(), + c if !c.is_ascii() && c.is_emoji_char() => self.invalid_ident_or_prefix(), _ => Unknown, }; let res = Token::new(token_kind, self.pos_within_token()); @@ -552,17 +552,16 @@ impl Cursor<'_> { // we see a prefix here, it is definitely an unknown prefix. match self.first() { '#' | '"' | '\'' => UnknownPrefix, - c if !c.is_ascii() && c.is_emoji_char() => self.fake_ident_or_unknown_prefix(), + c if !c.is_ascii() && c.is_emoji_char() => self.invalid_ident_or_prefix(), _ => Ident, } } - fn fake_ident_or_unknown_prefix(&mut self) -> TokenKind { + fn invalid_ident_or_prefix(&mut self) -> TokenKind { // Start is already eaten, eat the rest of identifier. self.eat_while(|c| { - unicode_xid::UnicodeXID::is_xid_continue(c) - || (!c.is_ascii() && c.is_emoji_char()) - || c == '\u{200d}' + const ZERO_WIDTH_JOINER: char = '\u{200d}'; + is_id_continue(c) || (!c.is_ascii() && c.is_emoji_char()) || c == ZERO_WIDTH_JOINER }); // Known prefixes must have been handled earlier. So if // we see a prefix here, it is definitely an unknown prefix. |
