diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-11-09 19:16:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-09 19:16:43 +0100 |
| commit | 9b50092fdc8ffd40751e5e7efaa689a4e7ac2b56 (patch) | |
| tree | ec122eb26e5604d04c8df181c356c8f5dfb849c3 /compiler | |
| parent | b73478b6ee1ed915ac3727da02d4675835588538 (diff) | |
| parent | 1990f1560801ca3f9e6a3286e58204aa329ee037 (diff) | |
| download | rust-9b50092fdc8ffd40751e5e7efaa689a4e7ac2b56.tar.gz rust-9b50092fdc8ffd40751e5e7efaa689a4e7ac2b56.zip | |
Rollup merge of #132341 - compiler-errors:raw-lt-prefix-id, r=chenyukang
Reject raw lifetime followed by `'`, like regular lifetimes do See comment. We want to reject cases like `'r#long'id`, which currently gets interpreted as a raw lifetime (`'r#long`) followed by a lifetime (`'id`). This could have alternative lexes, such as an overlong char literal (`'r#long'`) followed by an identifier (`id`). To avoid committing to this in any case, let's reject the whole thing. `@mattheww,` is this what you were looking for in https://github.com/rust-lang/reference/pull/1603#issuecomment-2339237325? I'd say ignore the details about the specific error message (the fact that this gets reinterpreted as a char literal is 🤷), just that because this causes a lexer error we're effectively saving syntactical space like you wanted.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lexer/src/lib.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index b0ab50dd773..f9f2a14dbd2 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -715,7 +715,17 @@ impl Cursor<'_> { self.bump(); self.bump(); self.eat_while(is_id_continue); - return RawLifetime; + match self.first() { + '\'' => { + // Check if after skipping literal contents we've met a closing + // single quote (which means that user attempted to create a + // string with single quotes). + self.bump(); + let kind = Char { terminated: true }; + return Literal { kind, suffix_start: self.pos_within_token() }; + } + _ => return RawLifetime, + } } // Either a lifetime or a character literal with |
