Skip to content

Commit c2e1097

Browse files
authored
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``
2 parents 2c85069 + 9ef580f commit c2e1097

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

compiler/rustc_parse/src/parser/expr.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -2023,17 +2023,14 @@ impl<'a> Parser<'a> {
20232023
let recovered = self.recover_after_dot();
20242024
let token = recovered.as_ref().unwrap_or(&self.token);
20252025
match token::Lit::from_token(token) {
2026-
Some(token_lit) => {
2027-
match MetaItemLit::from_token_lit(token_lit, token.span) {
2026+
Some(lit) => {
2027+
match MetaItemLit::from_token_lit(lit, token.span) {
20282028
Ok(lit) => {
20292029
self.bump();
20302030
Some(lit)
20312031
}
20322032
Err(err) => {
2033-
let span = token.span;
2034-
let token::Literal(lit) = token.kind else {
2035-
unreachable!();
2036-
};
2033+
let span = token.uninterpolated_span();
20372034
self.bump();
20382035
report_lit_error(&self.sess, err, lit, span);
20392036
// Pack possible quotes and prefixes from the original literal into

tests/ui/parser/lit-err-in-macro.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
macro_rules! f {
2+
($abi:literal) => {
3+
extern $abi fn f() {}
4+
}
5+
}
6+
7+
f!("Foo"__);
8+
//~^ ERROR suffixes on string literals are invalid
9+
10+
fn main() {}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: suffixes on string literals are invalid
2+
--> $DIR/lit-err-in-macro.rs:7:4
3+
|
4+
LL | f!("Foo"__);
5+
| ^^^^^^^ invalid suffix `__`
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)