rust-lang / rust-lang/rust-analyzer

Trying to rename "use alias" in VSCode messes up with files from other crates

Open
#5,198 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello. I'm not sure what is the "official" name of the renaming imports construct in Rust, so I'm referring to it as "use alias" both in the title and in the body of this issue. Fell free to fix this and delete this part, please.

What is wrong?

When trying to rename the "alias" part of the "use alias" using the Rename Symbol functionality from VSCode (F2), the original name is the one that gets replaced. Moreover, it seems that the change is applied to every source file that uses the previous original name as a mod name in every crate we depend on.

What should happen instead?

I expected that only the new name and its corresponding usages in the current file be changed.

MWE

main.rs

use std::io as foo;

fn main() {
    let _ = foo::empty();
    println!("Hello, world!");
}

Cargo.toml

Just the most basic

Steps taken

  1. click on the foo "alias"
  2. use the "Rename Symbol" utility (F2)
  3. enter the value "bar"
  4. bug!
    4.1. A lot of files get opened by VSCode, none of them from our crate
    4.2 All of the opened files have changes relating to the renaming we tried to do

System info

  • Using VSCode 1.46.1
    • rust-analyser 0.2.224 extension
  • Using rustc 1.44.1

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 with the minimal main.rs and Cargo.toml example, then reproduce the VSCode F2 rename on the foo alias from std::io. Inspect the rename behavior across the current crate and dependent crates. Done means renaming foo to bar changes only the alias and its corresponding usages in the current file, without opening or modifying unrelated files.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.