rust-lang / rust-lang/rust-analyzer
"Inline variable" code action is buggy when variable is shadowed
Nobody has claimed this yet.
- 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
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 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