Skip to content

Commit 1ffa5de

Browse files
authored
Rollup merge of rust-lang#122400 - wutchzone:122345, r=fmease
Fix ICE in diagnostics for parenthesized type arguments The second time is the charm 🤞 😁 Fixes rust-lang#122345 r? fmease
2 parents dff680d + eab1f30 commit 1ffa5de

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

compiler/rustc_parse/src/parser/path.rs

+31-21
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,25 +464,31 @@ impl<'a> Parser<'a> {
460464
CommaRecoveryMode::LikelyTuple,
461465
)
462466
})
463-
.is_ok()))
464-
&& !matches!(self.token.kind, token::ModSep | token::RArrow)
465-
{
466-
error.span_suggestion_verbose(
467-
prev_token_before_parsing.span,
468-
format!(
469-
"consider removing the `::` here to {}",
470-
match style {
471-
PathStyle::Expr => "call the expression",
472-
PathStyle::Pat => "turn this into a tuple struct pattern",
473-
_ => {
474-
return;
475-
}
476-
}
477-
),
478-
"",
479-
Applicability::MaybeIncorrect,
480-
);
467+
.map_err(|error| error.cancel()) => {}
468+
_ => {
469+
return;
470+
}
481471
}
472+
473+
if let token::ModSep | token::RArrow = self.token.kind {
474+
return;
475+
}
476+
477+
error.span_suggestion_verbose(
478+
prev_token_before_parsing.span,
479+
format!(
480+
"consider removing the `::` here to {}",
481+
match style {
482+
PathStyle::Expr => "call the expression",
483+
PathStyle::Pat => "turn this into a tuple struct pattern",
484+
_ => {
485+
return;
486+
}
487+
}
488+
),
489+
"",
490+
Applicability::MaybeIncorrect,
491+
);
482492
}
483493

484494
/// Parses generic args (within a path segment) with recovery for extra leading angle brackets.
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)