diff options
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/messages.ftl | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 18 |
3 files changed, 25 insertions, 22 deletions
diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index fd96d95bc2e..c2201b1c41e 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -323,10 +323,10 @@ parse_incorrect_semicolon = .suggestion = remove this semicolon .help = {$name} declarations are not followed by a semicolon -parse_incorrect_use_of_await = - incorrect use of `await` +parse_incorrect_use_of_await = incorrect use of `await` .parentheses_suggestion = `await` is not a method call, remove the parentheses - .postfix_suggestion = `await` is a postfix operation + +parse_incorrect_use_of_await_postfix_suggestion = `await` is a postfix operation parse_incorrect_visibility_restriction = incorrect visibility restriction .help = some possible visibility restrictions are: diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 18a3153bcd4..eee17a73acf 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -103,19 +103,26 @@ pub(crate) struct IncorrectUseOfAwait { pub span: Span, } +#[derive(Subdiagnostic)] +#[multipart_suggestion( + parse_incorrect_use_of_await_postfix_suggestion, + applicability = "machine-applicable" +)] +pub(crate) struct AwaitSuggestion { + #[suggestion_part(code = "")] + pub removal: Span, + #[suggestion_part(code = ".await{question_mark}")] + pub dot_await: Span, + pub question_mark: &'static str, +} + #[derive(Diagnostic)] #[diag(parse_incorrect_use_of_await)] pub(crate) struct IncorrectAwait { #[primary_span] pub span: Span, - #[suggestion( - parse_postfix_suggestion, - style = "verbose", - code = "{expr}.await{question_mark}" - )] - pub sugg_span: (Span, Applicability), - pub expr: String, - pub question_mark: &'static str, + #[subdiagnostic] + pub suggestion: AwaitSuggestion, } #[derive(Diagnostic)] diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 63e4d8a4352..39f1d4e89ec 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -3,8 +3,8 @@ use super::{ BlockMode, CommaRecoveryMode, Parser, PathStyle, Restrictions, SemiColonMode, SeqSep, TokenType, }; use crate::errors::{ - AddParen, AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, BadQPathStage2, - BadTypePlus, BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained, + AddParen, AmbiguousPlus, AsyncMoveBlockIn2015, AttributeOnParamType, AwaitSuggestion, + BadQPathStage2, BadTypePlus, BadTypePlusSub, ColonAsSemi, ComparisonOperatorsCannotBeChained, ComparisonOperatorsCannotBeChainedSugg, ConstGenericWithoutBraces, ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType, DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg, @@ -1959,18 +1959,14 @@ impl<'a> Parser<'a> { is_question: bool, ) -> (Span, ErrorGuaranteed) { let span = lo.to(hi); - let applicability = match expr.kind { - ExprKind::Try(_) => Applicability::MaybeIncorrect, // `await <expr>?` - _ => Applicability::MachineApplicable, - }; - let guar = self.dcx().emit_err(IncorrectAwait { span, - sugg_span: (span, applicability), - expr: self.span_to_snippet(expr.span).unwrap_or_else(|_| pprust::expr_to_string(expr)), - question_mark: if is_question { "?" } else { "" }, + suggestion: AwaitSuggestion { + removal: lo.until(expr.span), + dot_await: expr.span.shrink_to_hi(), + question_mark: if is_question { "?" } else { "" }, + }, }); - (span, guar) } |
