`type annotations needed` for `if let Some(whatever) = todo!() {` not very helpful
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn main() {
if let Some(whatever) = todo!() {
todo!();
} else {
todo!();
}
}
Current output
error[E0282]: type annotations needed
--> src/main.rs:2:17
|
2 | if let Some(whatever) = todo!() {
| ^^^^^^^^ cannot infer type
For more information about this error, try `rustc --explain E0282`.
It's not really clear how rustc would like to see the type annotations, without adding an extra binding and without type_ascription
What does not work:
if let Some(whatever): Option<i32> = todo!() {
or
if let Some(whatever: i32) = todo!() {
what did end up working:
if let Some(x) = Some(todo!()) {
or
if let Some(x @ ()) = todo!() {
Rust Version
rustc 1.89.0-nightly (6f6971078 2025-05-28)
binary: rustc
commit-hash: 6f69710780d579b180ab38da4c1384d630f7bd31
commit-date: 2025-05-28
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
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.
Research direction
Start by reproducing the supplied Rust example with the noted nightly version and compare the current E0282 diagnostic with the issue's working alternatives. Trace the compiler diagnostic path that reports “cannot infer type”; done means the error explains how to provide a useful annotation for this pattern without requiring an extra binding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100