diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-01 14:30:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-01 14:30:08 +0100 |
| commit | 337c48cec54f3e88d503f759796dfa925d94072b (patch) | |
| tree | ce7a3a0d90e874de82383740ff85e974c7b9c60c /compiler/rustc_parse/src | |
| parent | b57415839486893b1605d92d40918a90ffa653b1 (diff) | |
| parent | d878fd8877669005ee05de0c5c60021109580934 (diff) | |
| download | rust-337c48cec54f3e88d503f759796dfa925d94072b.tar.gz rust-337c48cec54f3e88d503f759796dfa925d94072b.zip | |
Rollup merge of #133482 - compiler-errors:raw-lt-tick, r=estebank
Only error raw lifetime followed by `\'` in edition 2021+ Fixes #133479 cc #132341 I think this fixes a purely theoretical regression since it only affects edition 2015 (who is using that?) and only in the very rare case of a raw lifetime followed immediately by a lifetime like `'r#a'r`.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/lexer/mod.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 8a42cf388f9..d97f05dc7eb 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -300,6 +300,26 @@ impl<'psess, 'src> Lexer<'psess, 'src> { let prefix_span = self.mk_sp(start, ident_start); if prefix_span.at_least_rust_2021() { + // If the raw lifetime is followed by \' then treat it a normal + // lifetime followed by a \', which is to interpret it as a character + // literal. In this case, it's always an invalid character literal + // since the literal must necessarily have >3 characters (r#...) inside + // of it, which is invalid. + if self.cursor.as_str().starts_with('\'') { + let lit_span = self.mk_sp(start, self.pos + BytePos(1)); + let contents = self.str_from_to(start + BytePos(1), self.pos); + emit_unescape_error( + self.dcx(), + contents, + lit_span, + lit_span, + Mode::Char, + 0..contents.len(), + EscapeError::MoreThanOneChar, + ) + .expect("expected error"); + } + let span = self.mk_sp(start, self.pos); let lifetime_name_without_tick = @@ -371,8 +391,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { rustc_lexer::TokenKind::Caret => token::BinOp(token::Caret), rustc_lexer::TokenKind::Percent => token::BinOp(token::Percent), - rustc_lexer::TokenKind::Unknown - | rustc_lexer::TokenKind::InvalidIdent => { + rustc_lexer::TokenKind::Unknown | rustc_lexer::TokenKind::InvalidIdent => { // Don't emit diagnostics for sequences of the same invalid token if swallow_next_invalid > 0 { swallow_next_invalid -= 1; |
