Skip to content

Commit a419aaf

Browse files
Rollup merge of #157978 - TaKO8Ki:fix-raw-ref-trailing-comma-recovery, r=JonathanBrouwer
Avoid `&raw` recovery ICE after trailing comma Fixes #157950 This is a follow up to #157888. For `&raw x,)`, recovery first skips `x`, then consumes the trailing comma. The old condition then fell through to `parse_token_tree()` when the next token was `)`, which causes an ICE.
2 parents ff81679 + 034044f commit a419aaf

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,10 @@ impl<'a> Parser<'a> {
13041304
let err_span = self.prev_token.span.to(self.token.span);
13051305
let mut args = thin_vec![self.mk_expr_err(err_span, guar)];
13061306
while !self.token.kind.is_close_delim_or_eof() {
1307-
if self.eat(exp!(Comma)) && !self.token.kind.is_close_delim_or_eof() {
1308-
args.push(self.mk_expr_err(self.prev_token.span.shrink_to_hi(), guar));
1307+
if self.eat(exp!(Comma)) {
1308+
if !self.token.kind.is_close_delim_or_eof() {
1309+
args.push(self.mk_expr_err(self.prev_token.span.shrink_to_hi(), guar));
1310+
}
13091311
} else {
13101312
self.parse_token_tree();
13111313
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/157950.
2+
3+
fn main() {
4+
takes_raw_ptr_args(&raw x,)
5+
//~^ ERROR expected one of
6+
//~| ERROR cannot find function `takes_raw_ptr_args` in this scope
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `const`, `mut`, `{`, or an operator, found `x`
2+
--> $DIR/raw-no-const-mut-trailing-comma.rs:4:29
3+
|
4+
LL | takes_raw_ptr_args(&raw x,)
5+
| ^ expected one of 10 possible tokens
6+
|
7+
help: `&raw` must be followed by `const` or `mut` to be a raw reference expression
8+
|
9+
LL | takes_raw_ptr_args(&raw const x,)
10+
| +++++
11+
LL | takes_raw_ptr_args(&raw mut x,)
12+
| +++
13+
14+
error[E0425]: cannot find function `takes_raw_ptr_args` in this scope
15+
--> $DIR/raw-no-const-mut-trailing-comma.rs:4:5
16+
|
17+
LL | takes_raw_ptr_args(&raw x,)
18+
| ^^^^^^^^^^^^^^^^^^ not found in this scope
19+
20+
error: aborting due to 2 previous errors
21+
22+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)