rust-lang / rust-lang/rust-analyzer
"Wrap in Some" with if/else and inferred assignment incorrect
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer version: 0.3.3049-standalone
rustc version: rustc 1.98.1 (48a229cea 2026-09-01)
editor or extension: VSCode, rust-analyzer 0.3.3049
relevant settings:
repository link (if public, optional):
code snippet to reproduce:
// Run the "Wrap in Some" action on '123'
let x = if { None } else { 123 };
Result:
let x = if true { None } else Some({ 123 });
rust-analyzer wraps the entire block for the else branch with Some, instead of just the 123 that gets returned for the variable assignment.
If I set a type on x: Option<_>, this doesn't happen.
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
Reproduce the issue in VSCode with the provided Rust snippet by running the “Wrap in Some” action on 123. Locate the rust-analyzer implementation of that action and inspect how it chooses the expression in an inferred if/else assignment. Done means only 123 is wrapped, while the explicitly typed Option<_> case remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100