diff options
| author | Michael Goulet <michael@errs.io> | 2022-01-13 15:44:17 -0800 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-01-13 19:45:29 -0800 |
| commit | 867554ad7c571adea299ecb7ad99641ee22dc91b (patch) | |
| tree | 13e5b1161c683af9530c03d4165e7fe5450f9123 /compiler/rustc_parse/src/parser/diagnostics.rs | |
| parent | 256721ee519f6ff15dc5c1cfaf3ebf9af75efa4a (diff) | |
| download | rust-867554ad7c571adea299ecb7ad99641ee22dc91b.tar.gz rust-867554ad7c571adea299ecb7ad99641ee22dc91b.zip | |
Fix suggesting turbofish with lifetime arguments
Diffstat (limited to 'compiler/rustc_parse/src/parser/diagnostics.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 4121a759c37..19d6de09dae 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -27,7 +27,7 @@ use std::mem::take; use tracing::{debug, trace}; const TURBOFISH_SUGGESTION_STR: &str = - "use `::<...>` instead of `<...>` to specify type or const arguments"; + "use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments"; /// Creates a placeholder argument. pub(super) fn dummy_arg(ident: Ident) -> Param { @@ -731,21 +731,28 @@ impl<'a> Parser<'a> { match x { Ok((_, _, false)) => { if self.eat(&token::Gt) { - match self.parse_expr() { - Ok(_) => { - e.span_suggestion_verbose( - binop.span.shrink_to_lo(), - TURBOFISH_SUGGESTION_STR, - "::".to_string(), - Applicability::MaybeIncorrect, - ); - e.emit(); - *expr = - self.mk_expr_err(expr.span.to(self.prev_token.span)); - return Ok(()); - } - Err(mut err) => { - err.cancel(); + let turbo_err = e.span_suggestion_verbose( + binop.span.shrink_to_lo(), + TURBOFISH_SUGGESTION_STR, + "::".to_string(), + Applicability::MaybeIncorrect, + ); + if self.check(&TokenKind::Semi) { + turbo_err.emit(); + *expr = self.mk_expr_err(expr.span); + return Ok(()); + } else { + match self.parse_expr() { + Ok(_) => { + turbo_err.emit(); + *expr = self + .mk_expr_err(expr.span.to(self.prev_token.span)); + return Ok(()); + } + Err(mut err) => { + turbo_err.cancel(); + err.cancel(); + } } } } |
