Skip to content

Commit

Permalink
Rollup merge of rust-lang#112642 - compiler-errors:interp-lit-err, r=…
Browse files Browse the repository at this point in the history
…nnethercote

Handle interpolated literal errors

Not sure why it was doing a whole dance to re-match on the token kind when it seems like `Lit::from_token` does the right thing for both macro-arg and regular literals. Nothing seems to have regressed diagnostics-wise from the change, though.

Fixes rust-lang#112622

r? `@nnethercote`
  • Loading branch information
matthiaskrgr authored Jun 16, 2023
2 parents 235cf4d + 9ef580f commit e415075
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 3 additions & 6 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/parser/lit-err-in-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
macro_rules! f {
($abi:literal) => {
extern $abi fn f() {}
}
}

f!("Foo"__);
//~^ ERROR suffixes on string literals are invalid

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/parser/lit-err-in-macro.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e415075

Please sign in to comment.