diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-14 20:12:05 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-02-15 14:46:08 +1100 |
| commit | 25ed6e43b0ea03ca48692741624f3e70d717ea43 (patch) | |
| tree | 7c4dc20f60c6c62d239cd710400998f405ab1bd8 /compiler/rustc_parse/src/lexer/mod.rs | |
| parent | 332c57723a03e97497d6fba6636e31c2e41fefe9 (diff) | |
| download | rust-25ed6e43b0ea03ca48692741624f3e70d717ea43.tar.gz rust-25ed6e43b0ea03ca48692741624f3e70d717ea43.zip | |
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
Diffstat (limited to 'compiler/rustc_parse/src/lexer/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/lexer/mod.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 7502a556794..c768ea93b5f 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -481,8 +481,8 @@ impl<'sess, 'src> StringReader<'sess, 'src> { let mut kind = token::Integer; if empty_int { let span = self.mk_sp(start, end); - self.dcx().emit_err(errors::NoDigitsLiteral { span }); - kind = token::Err; + let guar = self.dcx().emit_err(errors::NoDigitsLiteral { span }); + kind = token::Err(guar); } else if matches!(base, Base::Binary | Base::Octal) { let base = base as u32; let s = self.str_from_to(start + BytePos(2), end); @@ -492,8 +492,9 @@ impl<'sess, 'src> StringReader<'sess, 'src> { start + BytePos::from_usize(2 + idx + c.len_utf8()), ); if c != '_' && c.to_digit(base).is_none() { - self.dcx().emit_err(errors::InvalidDigitLiteral { span, base }); - kind = token::Err; + let guar = + self.dcx().emit_err(errors::InvalidDigitLiteral { span, base }); + kind = token::Err(guar); } } } @@ -711,7 +712,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> { let hi = lo + BytePos(end - start); let span = self.mk_sp(lo, hi); let is_fatal = err.is_fatal(); - if let Some(_guar) = emit_unescape_error( + if let Some(guar) = emit_unescape_error( self.dcx(), lit_content, span_with_quotes, @@ -721,18 +722,19 @@ impl<'sess, 'src> StringReader<'sess, 'src> { err, ) { assert!(is_fatal); - kind = token::Err; + kind = token::Err(guar); } } }); // We normally exclude the quotes for the symbol, but for errors we // include it because it results in clearer error messages. - if kind != token::Err { - (kind, Symbol::intern(lit_content)) + let sym = if !matches!(kind, token::Err(_)) { + Symbol::intern(lit_content) } else { - (token::Err, self.symbol_from_to(start, end)) - } + self.symbol_from_to(start, end) + }; + (kind, sym) } fn cook_unicode( |
