rust-lang / rust-lang/rust-analyzer
New assist: change multiple `let` assignments of same variable to a `let` block
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I'd like to propose an assist that converts a common pattter of variable initialization by multiple let assignments of same variable (not sure if the pattern has a name) into a let x = {...}; block. I think it often assists with readability, especially if the reassignments are more complex.
This:
let is_even = "123";
let is_even: u32 = is_even.parse()?;
let is_even = is_even % 2 == 0;
into this:
let is_even = {
let is_even = "123";
let is_even: u32 = is_even.parse()?;
is_even % 2 == 0
};
and back.
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 reviewing rust-analyzer's existing assist framework and how assists handle transformations in both directions. Use the examples in the issue as the target behavior: combine repeated let assignments into a let block and convert that block back when applicable. Done means both transformations preserve the shown bindings and expressions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100