rust-lang / rust-lang/rust-analyzer

"Inline variable" code action is buggy when variable is shadowed

Open
#14,702 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I have a chunk of code that looks like this

fn foo(a: usize) -> usize {
  let b = a;
  let a = a + 1;
  b * 2;
}

If I place the cursor on b in let b = a;, and ask rust-analyzer to inline it, it happily produces

fn foo(a: usize) -> usize {
  let a = a + 1;
  a * 2;
}

which is not the same thing semantically.

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

2023-03-06

rustc version: (eg. output of rustc -V)

rustc 1.70.0-nightly (28a29282f 2023-04-06)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

accessed via rustic-mode in doom emacs

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 reproducing the inline-variable action with the shadowed a example in the issue. Trace the inline-variable code action and its handling of bindings, then verify that applying it preserves the original value and add coverage for this shadowing case if the relevant test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.