Add suggestion to remove if in let...else block

Adds an additional hint to failures where we encounter an else keyword
while we're parsing an if-let block.

This is likely that the user has accidentally mixed if-let and let...else
together.
This commit is contained in:
Edward Shen 2023-01-23 20:31:45 -08:00 committed by Edward Shen
parent c8e6a9e8b6
commit a8b77cfe54
No known key found for this signature in database
GPG key ID: D6A2AC5596760EE9
6 changed files with 61 additions and 14 deletions

View file

@ -337,7 +337,9 @@ pub(crate) struct IfExpressionMissingThenBlock {
#[primary_span]
pub if_span: Span,
#[subdiagnostic]
pub sub: IfExpressionMissingThenBlockSub,
pub missing_then_block_sub: IfExpressionMissingThenBlockSub,
#[subdiagnostic]
pub let_else_sub: Option<IfExpressionLetSomeSub>,
}
#[derive(Subdiagnostic)]
@ -348,6 +350,13 @@ pub(crate) enum IfExpressionMissingThenBlockSub {
AddThenBlock(#[primary_span] Span),
}
#[derive(Subdiagnostic)]
#[help(parse_extra_if_in_let_else)]
pub(crate) struct IfExpressionLetSomeSub {
#[primary_span]
pub if_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_if_expression_missing_condition)]
pub(crate) struct IfExpressionMissingCondition {