|
1 | 1 | use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
|
2 | 2 | use super::{Parser, Restrictions, TokenType};
|
3 | 3 | use crate::errors::PathSingleColon;
|
| 4 | +use crate::parser::{CommaRecoveryMode, RecoverColon, RecoverComma}; |
4 | 5 | use crate::{errors, maybe_whole};
|
5 | 6 | use ast::token::IdentIsRaw;
|
6 | 7 | use rustc_ast::ptr::P;
|
@@ -373,7 +374,52 @@ impl<'a> Parser<'a> {
|
373 | 374 | .into()
|
374 | 375 | } else {
|
375 | 376 | // `(T, U) -> R`
|
376 |
| - let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?; |
| 377 | + let prev_token_before_parsing = self.prev_token.clone(); |
| 378 | + |
| 379 | + let mut snapshot = None; |
| 380 | + if self.may_recover() |
| 381 | + && (self.token.can_begin_expr() || self.token.can_begin_pattern()) |
| 382 | + { |
| 383 | + snapshot = Some(self.create_snapshot_for_diagnostic()); |
| 384 | + } |
| 385 | + |
| 386 | + let (inputs, _) = match self.parse_paren_comma_seq(|p| p.parse_ty()) { |
| 387 | + Ok(output) => output, |
| 388 | + Err(mut error) if prev_token_before_parsing.kind == token::ModSep => { |
| 389 | + error.span_label(prev_token_before_parsing.span.with_hi(prev_token_before_parsing.span.hi() + BytePos(1)), "while parsing this list of parenthesized type arguments starting here"); |
| 390 | + |
| 391 | + if let Some(mut snapshot) = snapshot { |
| 392 | + if ((style == PathStyle::Expr |
| 393 | + && snapshot.parse_paren_comma_seq(|p| p.parse_expr()).is_ok()) |
| 394 | + || (style == PathStyle::Pat |
| 395 | + && snapshot |
| 396 | + .parse_paren_comma_seq(|p| { |
| 397 | + p.parse_pat_allow_top_alt( |
| 398 | + None, |
| 399 | + RecoverComma::No, |
| 400 | + RecoverColon::No, |
| 401 | + CommaRecoveryMode::LikelyTuple, |
| 402 | + ) |
| 403 | + }) |
| 404 | + .is_ok())) |
| 405 | + && snapshot.token.kind != token::ModSep |
| 406 | + && snapshot.token.kind != token::RArrow |
| 407 | + { |
| 408 | + { |
| 409 | + error.span_suggestion_verbose( |
| 410 | + prev_token_before_parsing.span, |
| 411 | + "consider removing `::`", |
| 412 | + "", |
| 413 | + Applicability::Unspecified, |
| 414 | + ); |
| 415 | + } |
| 416 | + } |
| 417 | + } |
| 418 | + |
| 419 | + return Err(error); |
| 420 | + } |
| 421 | + Err(error) => return Err(error), |
| 422 | + }; |
377 | 423 | let inputs_span = lo.to(self.prev_token.span);
|
378 | 424 | let output =
|
379 | 425 | self.parse_ret_ty(AllowPlus::No, RecoverQPath::No, RecoverReturnSign::No)?;
|
|
0 commit comments