diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-13 06:41:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-13 06:41:24 +0100 |
| commit | 1ffa5ded58aca5482c0763dd202fa6c202bd1eb9 (patch) | |
| tree | 2cee62a431ca64f3870a4320835ead52cf952321 /compiler/rustc_parse/src | |
| parent | dff680d35915008a75f0b90e17086833180c8478 (diff) | |
| parent | eab1f30c297027f2349ecd1322573ae3b5c9d668 (diff) | |
| download | rust-1ffa5ded58aca5482c0763dd202fa6c202bd1eb9.tar.gz rust-1ffa5ded58aca5482c0763dd202fa6c202bd1eb9.zip | |
Rollup merge of #122400 - wutchzone:122345, r=fmease
Fix ICE in diagnostics for parenthesized type arguments The second time is the charm :crossed_fingers: :grin: Fixes #122345 r? fmease
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 2edf2111de7..163d10d03f0 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -449,9 +449,13 @@ impl<'a> Parser<'a> { prev_token_before_parsing: Token, error: &mut Diag<'_>, ) { - if ((style == PathStyle::Expr && self.parse_paren_comma_seq(|p| p.parse_expr()).is_ok()) - || (style == PathStyle::Pat - && self + match style { + PathStyle::Expr + if let Ok(_) = self + .parse_paren_comma_seq(|p| p.parse_expr()) + .map_err(|error| error.cancel()) => {} + PathStyle::Pat + if let Ok(_) = self .parse_paren_comma_seq(|p| { p.parse_pat_allow_top_alt( None, @@ -460,25 +464,31 @@ impl<'a> Parser<'a> { CommaRecoveryMode::LikelyTuple, ) }) - .is_ok())) - && !matches!(self.token.kind, token::ModSep | token::RArrow) - { - error.span_suggestion_verbose( - prev_token_before_parsing.span, - format!( - "consider removing the `::` here to {}", - match style { - PathStyle::Expr => "call the expression", - PathStyle::Pat => "turn this into a tuple struct pattern", - _ => { - return; - } - } - ), - "", - Applicability::MaybeIncorrect, - ); + .map_err(|error| error.cancel()) => {} + _ => { + return; + } } + + if let token::ModSep | token::RArrow = self.token.kind { + return; + } + + error.span_suggestion_verbose( + prev_token_before_parsing.span, + format!( + "consider removing the `::` here to {}", + match style { + PathStyle::Expr => "call the expression", + PathStyle::Pat => "turn this into a tuple struct pattern", + _ => { + return; + } + } + ), + "", + Applicability::MaybeIncorrect, + ); } /// Parses generic args (within a path segment) with recovery for extra leading angle brackets. |
