Rollup merge of #118191 - estebank:let-chain-typo, r=compiler-errors
Suggest `let` or `==` on typo'd let-chain When encountering a bare assignment in a let-chain, suggest turning the assignment into a `let` expression or an equality check. ``` error: expected expression, found `let` statement --> $DIR/bad-if-let-suggestion.rs:5:8 | LL | if let x = 1 && i = 2 {} | ^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions help: you might have meant to continue the let-chain | LL | if let x = 1 && let i = 2 {} | +++ help: you might have meant to compare for equality | LL | if let x = 1 && i == 2 {} | + ```
This commit is contained in:
commit
aab61d0b9a
6 changed files with 93 additions and 18 deletions
|
@ -415,6 +415,32 @@ pub(crate) struct ExpectedExpressionFoundLet {
|
|||
pub span: Span,
|
||||
#[subdiagnostic]
|
||||
pub reason: ForbiddenLetReason,
|
||||
#[subdiagnostic]
|
||||
pub missing_let: Option<MaybeMissingLet>,
|
||||
#[subdiagnostic]
|
||||
pub comparison: Option<MaybeComparison>,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic, Clone, Copy)]
|
||||
#[multipart_suggestion(
|
||||
parse_maybe_missing_let,
|
||||
applicability = "maybe-incorrect",
|
||||
style = "verbose"
|
||||
)]
|
||||
pub(crate) struct MaybeMissingLet {
|
||||
#[suggestion_part(code = "let ")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic, Clone, Copy)]
|
||||
#[multipart_suggestion(
|
||||
parse_maybe_comparison,
|
||||
applicability = "maybe-incorrect",
|
||||
style = "verbose"
|
||||
)]
|
||||
pub(crate) struct MaybeComparison {
|
||||
#[suggestion_part(code = "=")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue