rust-lang / rust-lang/rust-analyzer

Renaming isn't aware of different namespaces

Open
#8,140 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Given the following source:


mod foo {
    pub mod bar {
        pub fn inner() {}
    }
    pub const bar: () = ();
}
use foo::bar;
fn main() {
    bar::inner();
}

renaming the const bar to something else like bar2 breaks the code as it emits:

mod foo {
    pub mod bar {
        pub fn inner() {}
    }
    pub const bar2: () = ();
}
use foo::bar2;
fn main() {
    bar::inner(); // now unresolved
}

The general problem already exists for path resolution as the preference there is kind of hardcoded at the moment, but even with that fixed renaming requires knowledge of whether a reference might be occupying multiple namespaces or not in use statements.

For consts this isn't too pressing of a matter as the capitalization is usually different, but for macros this can cause problems more easily as those names tend to clash with modules/functions.

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 rename implementation and its path-resolution handling, then trace how use statements and references are classified across Rust namespaces. Reproduce the example and verify that renaming the const preserves the module reference while also updating references that actually target the const, including macro-related cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.