Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle interpolated literal errors #112642

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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