rust-lang / rust-lang/rust-analyzer

"Wrap in Some" with if/else and inferred assignment incorrect

Open
#23,378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-bug E-easy good first issue
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.