Handle interpolated literal errors

This commit is contained in:
Michael Goulet 2023-06-15 01:55:30 +00:00
parent 6330daade9
commit 9ef580fa6f
3 changed files with 21 additions and 6 deletions

View File

@ -2023,17 +2023,14 @@ impl<'a> Parser<'a> {
let recovered = self.recover_after_dot();
let token = recovered.as_ref().unwrap_or(&self.token);
match token::Lit::from_token(token) {
Some(token_lit) => {
match MetaItemLit::from_token_lit(token_lit, token.span) {
Some(lit) => {
match MetaItemLit::from_token_lit(lit, token.span) {
Ok(lit) => {
self.bump();
Some(lit)
}
Err(err) => {
let span = token.span;
let token::Literal(lit) = token.kind else {
unreachable!();
};
let span = token.uninterpolated_span();
self.bump();
report_lit_error(&self.sess, err, lit, span);
// Pack possible quotes and prefixes from the original literal into

View File

@ -0,0 +1,10 @@
macro_rules! f {
($abi:literal) => {
extern $abi fn f() {}
}
}
f!("Foo"__);
//~^ ERROR suffixes on string literals are invalid
fn main() {}

View File

@ -0,0 +1,8 @@
error: suffixes on string literals are invalid
--> $DIR/lit-err-in-macro.rs:7:4
|
LL | f!("Foo"__);
| ^^^^^^^ invalid suffix `__`
error: aborting due to previous error