diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-06-16 14:46:17 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-16 14:46:17 +0530 |
| commit | c2e109744db3322f44ebfbe707847bbb9b9be933 (patch) | |
| tree | f728efaf54e915d106a8042fb302b33588d94c48 | |
| parent | 2c850691c11d3400c08ba9680a000d8d1cc2eae6 (diff) | |
| parent | 9ef580fa6f2b5019b35e6a9cf979f6f13d21de00 (diff) | |
Rollup merge of #112642 - compiler-errors:interp-lit-err, r=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 #112622 r? ``@nnethercote``
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 9 | ||||
| -rw-r--r-- | tests/ui/parser/lit-err-in-macro.rs | 10 | ||||
| -rw-r--r-- | tests/ui/parser/lit-err-in-macro.stderr | 8 |
3 files changed, 21 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index cea2a71c988..f00bc54589a 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -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 diff --git a/tests/ui/parser/lit-err-in-macro.rs b/tests/ui/parser/lit-err-in-macro.rs new file mode 100644 index 00000000000..cff8ee6b40c --- /dev/null +++ b/tests/ui/parser/lit-err-in-macro.rs @@ -0,0 +1,10 @@ +macro_rules! f { + ($abi:literal) => { + extern $abi fn f() {} + } +} + +f!("Foo"__); +//~^ ERROR suffixes on string literals are invalid + +fn main() {} diff --git a/tests/ui/parser/lit-err-in-macro.stderr b/tests/ui/parser/lit-err-in-macro.stderr new file mode 100644 index 00000000000..a61fb5c85d4 --- /dev/null +++ b/tests/ui/parser/lit-err-in-macro.stderr @@ -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 + |
