Rust suggests adding `else` to non-let assignment.
Open
@xizheyin is already working on this.
Since Aug 18, 2025.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn main() {
let mut x = 1;
Some(x) = Some(1);
}
Current output
error[E0005]: refutable pattern in local binding
--> src/main.rs:3:5
|
3 | Some(x) = Some(1);
| ^^^^^^^ pattern `None` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `Option<i32>`
help: you might want to use `let else` to handle the variant that isn't matched
|
3 | Some(x) = Some(1) else { todo!() };
| ++++++++++++++++
For more information about this error, try `rustc --explain E0005`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Desired output
Rationale and extra context
Adding the else as suggested results in a parse error.
Other cases
Rust Version
Reproducible on the playground with version 1.91.0-nightly (2025-08-16 2e2642e641a941f0a140)
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.