Skip to content

Commit 9e029cb

Browse files
committed
fix consume token
1 parent 377c3c7 commit 9e029cb

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,16 @@ impl<'a> Parser<'a> {
15671567
let guar = report_lit_error(&self.psess, err, token_lit, span);
15681568
let token_lit = token::Lit::new(token::Err(guar), token_lit.symbol, None);
15691569
let expr = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Lit(token_lit));
1570+
1571+
// Try to consume the next token if it looks like another string literal
1572+
// This prevents cascading errors when raw strings with invalid suffixes
1573+
// are immediately followed by another string
1574+
if let TokenKind::Literal(lit) = &self.token.kind {
1575+
if matches!(lit.kind, token::LitKind::Str | token::LitKind::StrRaw(_)) {
1576+
self.bump();
1577+
}
1578+
}
1579+
15701580
return self.maybe_recover_from_bad_qpath(expr);
15711581
}
15721582
let expr = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Lit(token_lit));
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Test for issue #144161: Wrong error for string literal suffix when stuck together
2-
// This tests the case where a raw string has an invalid suffix immediately followed by another string
32

43
fn main() {
54
let s = r#" \\ "#r"\\ ";
65
//~^ ERROR suffixes on string literals are invalid
7-
//~| ERROR expected one of `.`, `;`, `?`, `else`, or an operator
86
}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
error: suffixes on string literals are invalid
2-
--> $DIR/raw-string-suffix-invalid.rs:5:13
2+
--> $DIR/raw-string-suffix-invalid.rs:4:13
33
|
44
LL | let s = r#" \ "#r"\ ";
55
| ^^^^^^^^^^ invalid suffix `r`
66

7-
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `"\ "`
8-
--> $DIR/raw-string-suffix-invalid.rs:5:23
9-
|
10-
LL | let s = r#" \ "#r"\ ";
11-
| ^^^^^ expected one of `.`, `;`, `?`, `else`, or an operator
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
148

0 commit comments

Comments
 (0)