Skip to content

Commit 0ce07fc

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

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

compiler/rustc_parse/src/parser/path.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,13 @@ 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())
453-
|| (style == PathStyle::Pat
454-
&& self
452+
match style {
453+
PathStyle::Expr
454+
if let Ok(_) = self
455+
.parse_paren_comma_seq(|p| p.parse_expr())
456+
.map_err(|error| error.cancel()) => {}
457+
PathStyle::Pat
458+
if let Ok(_) = self
455459
.parse_paren_comma_seq(|p| {
456460
p.parse_pat_allow_top_alt(
457461
None,
@@ -460,9 +464,13 @@ impl<'a> Parser<'a> {
460464
CommaRecoveryMode::LikelyTuple,
461465
)
462466
})
463-
.is_ok()))
464-
&& !matches!(self.token.kind, token::ModSep | token::RArrow)
465-
{
467+
.map_err(|error| error.cancel()) => {}
468+
_ => {
469+
return;
470+
}
471+
}
472+
473+
if !matches!(self.token.kind, token::ModSep | token::RArrow) {
466474
error.span_suggestion_verbose(
467475
prev_token_before_parsing.span,
468476
format!(
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)