- Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.F-let_chains`#![feature(let_chains)]``#![feature(let_chains)]`P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn main() { let x = Some(42); if let Some(_) = x && Some(x) = x {} }
Current output
Update:
error: expected expression, found `let` statement --> src/main.rs:3:8 | 3 | if let Some(_) = x | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions help: you might have meant to continue the let-chain | 4 | && let Some(x) = x | +++ help: you might have meant to compare for equality | 4 | && Some(x) == x | + error[E0308]: mismatched types --> src/main.rs:4:12 | 4 | && Some(x) = x | ^^^^^^^ expected `bool`, found `Option<Option<{integer}>>` | = note: expected type `bool` found enum `Option<Option<{integer}>>` help: use `Option::is_some` to test if the `Option` has a value | 4 | && Some(x).is_some() = x | ++++++++++ error[E0308]: mismatched types --> src/main.rs:3:8 | 3 | if let Some(_) = x | ________^ 4 | | && Some(x) = x | |______________________^ expected `bool`, found `()`
Previously:
error: expected expression, found `let` statement --> src/main.rs:3:8 | 3 | if let Some(_) = x | ^^^^^^^^^^^^^^^ | = note: only supported directly in conditions of `if` and `while` expressions error[E0308]: mismatched types --> src/main.rs:4:12 | 4 | && Some(x) = x | ^^^^^^^ expected `bool`, found `Option<Option<{integer}>>` | = note: expected type `bool` found enum `Option<Option<{integer}>>` help: use `Option::is_some` to test if the `Option` has a value | 4 | && Some(x).is_some() = x | ++++++++++ error[E0308]: mismatched types --> src/main.rs:3:8 | 3 | if let Some(_) = x | ________^ 4 | | && Some(x) = x | |______________________^ expected `bool`, found `()`
Desired output
Edit: we now provide appropriate suggestions in the first diagnostic, but we should notice that this should have been a let
chain and silence the E0308 errors.
error: let-chain with missing `let` --> src/main.rs:3:8 | 3 | if let Some(_) = x | --------------- let-chain starting here 4 | && Some(x) = x | ^^^^^^^^^^^ expected `let` expression, found assignment | help: add `let` before the expression | 4 | && let Some(x) = x | +++
Rationale and extra context
No response
Other cases
No response
Anything else?
No response
fmease, mattfbacon, obeis and ClementNerma
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.F-let_chains`#![feature(let_chains)]``#![feature(let_chains)]`P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.