rust-lang / rust-lang/rust-analyzer

New assist: change multiple `let` assignments of same variable to a `let` block

Open
#15,703 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.