rust-lang / rust-lang/rust-analyzer
Autoimport doesn't account for overloaded symbols
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Example:
mod foo {
pub mod bar {
pub fn baz() {}
}
pub fn bar() {}
}
use crate::foo::bar;
fn main() {
bar();
// v
foo::bar::baz();
}
If we put the cursor on baz right under v in the comment and invoke Replace qualified path with use assist.
The following changes will be made:
mod foo {
pub mod bar {
pub fn baz() {}
}
pub fn bar() {}
}
- use crate::foo::bar;
+ use crate::foo::bar::{self, baz};
fn main() {
bar();
foo::bar::baz();
}
which results in invalid code because bar symbol is now imported via self which is only available for module namespace, so bar() call is broken.
Also, when running that assist only the use statement is updated, foo::bar::baz isn't reduced to just baz(), but that looks like an unrelated problem?
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 at the implementation of the “Replace qualified path with use” assist and its existing tests; reproduce the provided overloaded module/function example. Ensure the assist preserves the valid bar() call while importing baz, then add a regression test and separately verify whether path shortening is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100