Improve ternary operator recovery
This commit is contained in:
@@ -436,10 +436,28 @@ pub(crate) enum IfExpressionMissingThenBlockSub {
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_ternary_operator)]
|
||||
#[help]
|
||||
pub(crate) struct TernaryOperator {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
/// If we have a span for the condition expression, suggest the if/else
|
||||
#[subdiagnostic]
|
||||
pub sugg: Option<TernaryOperatorSuggestion>,
|
||||
/// Otherwise, just print the suggestion message
|
||||
#[help(parse_use_if_else)]
|
||||
pub no_sugg: bool,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic, Copy, Clone)]
|
||||
#[multipart_suggestion(parse_use_if_else, applicability = "maybe-incorrect", style = "verbose")]
|
||||
pub(crate) struct TernaryOperatorSuggestion {
|
||||
#[suggestion_part(code = "if ")]
|
||||
pub before_cond: Span,
|
||||
#[suggestion_part(code = "{{")]
|
||||
pub question: Span,
|
||||
#[suggestion_part(code = "}} else {{")]
|
||||
pub colon: Span,
|
||||
#[suggestion_part(code = " }}")]
|
||||
pub end: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
||||
Reference in New Issue
Block a user