Skip to content

Commit ff7ffc8

Browse files
committed
Fix ICE in diagnostics for parenthesized type arguments
1 parent 7de1a1f commit ff7ffc8

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_parse/src/parser/path.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,11 @@ impl<'a> Parser<'a> {
449449
prev_token_before_parsing: Token,
450450
error: &mut Diag<'_>,
451451
) {
452-
if ((style == PathStyle::Expr && self.parse_paren_comma_seq(|p| p.parse_expr()).is_ok())
452+
if ((style == PathStyle::Expr
453+
&& self
454+
.parse_paren_comma_seq(|p| p.parse_expr())
455+
.map_err(|error| error.cancel())
456+
.is_ok())
453457
|| (style == PathStyle::Pat
454458
&& self
455459
.parse_paren_comma_seq(|p| {
@@ -460,6 +464,7 @@ impl<'a> Parser<'a> {
460464
CommaRecoveryMode::LikelyTuple,
461465
)
462466
})
467+
.map_err(|error| error.cancel())
463468
.is_ok()))
464469
&& !matches!(self.token.kind, token::ModSep | token::RArrow)
465470
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
unsafe {
3+
dealloc(ptr2, Layout::(x: !)(1, 1)); //~ ERROR: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
4+
//~^ ERROR: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
5+
//~| while parsing this parenthesized list of type arguments starting here
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `:`
2+
--> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:3:33
3+
|
4+
LL | dealloc(ptr2, Layout::(x: !)(1, 1));
5+
| --- ^ expected one of 7 possible tokens
6+
| |
7+
| while parsing this parenthesized list of type arguments starting here
8+
9+
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
10+
--> $DIR/diagnostics-parenthesized-type-arguments-ice-issue-122345.rs:3:43
11+
|
12+
LL | dealloc(ptr2, Layout::(x: !)(1, 1));
13+
| ^ expected one of `.`, `;`, `?`, `}`, or an operator
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)