diff options
| author | Michael Goulet <michael@errs.io> | 2024-09-05 05:43:55 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-09-06 10:32:48 -0400 |
| commit | 97910580aadab067ef13b5d0094a57e124c743ea (patch) | |
| tree | 8fd86ff49b72fb83a0a446c860b543ef9cbf6606 /compiler/rustc_lexer | |
| parent | 3b3e43a386a9b89609fe529921bdd49ba3511fb8 (diff) | |
| download | rust-97910580aadab067ef13b5d0094a57e124c743ea.tar.gz rust-97910580aadab067ef13b5d0094a57e124c743ea.zip | |
Add initial support for raw lifetimes
Diffstat (limited to 'compiler/rustc_lexer')
| -rw-r--r-- | compiler/rustc_lexer/src/lib.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index 6561e416cfa..60aab668cba 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -97,6 +97,9 @@ pub enum TokenKind { /// and not the separator. UnknownPrefixLifetime, + /// `'r#lt`, which in edition < 2021 is split into several tokens: `'r # lt`. + RawLifetime, + /// Similar to the above, but *always* an error on every edition. This is used /// for emoji identifier recovery, as those are not meant to be ever accepted. InvalidPrefix, @@ -683,9 +686,17 @@ impl Cursor<'_> { return Literal { kind, suffix_start }; } + if self.first() == 'r' && self.second() == '#' && is_id_start(self.third()) { + // Eat "r" and `#`, and identifier start characters. + self.bump(); + self.bump(); + self.bump(); + self.eat_while(is_id_continue); + return RawLifetime; + } + // Either a lifetime or a character literal with // length greater than 1. - let starts_with_number = self.first().is_ascii_digit(); // Skip the literal contents. |
