rust-lang / rust-lang/rust-analyzer
"Remove all the unused imports" doesn't detect item-like usage of imports correctly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
main.rs
use sub1::Foo;
mod sub1;
mod sub2;
fn main() {
sub2::do_something();
}
sub1.rs:
#[derive(Debug)]
pub struct Foo;
sub2.rs:
pub fn do_something() {
let f = crate::Foo;
dbg!(f);
}
The "remove all the unused imports" is suggested for use sub1::Foo; in main. If applied, it removes the import, invalidating the code in sub2.rs which tries to use crate::Foo, which is valid because imports are item-like, and can be imported as such.
This seems to only happen if the modules are in different files. The following code, which inlines all the modules does not cause this behavior. The assist is not suggested:
use sub1::Foo;
mod sub1 {
#[derive(Debug)]
pub struct Foo;
}
mod sub2 {
pub fn do_something() {
let f = crate::Foo;
dbg!(f);
}
}
fn main() {
sub2::do_something();
}
rust-analyzer version 0.3.1615-standalone
rustc version: rustc 1.73.0-nightly (04abc370b 2023-07-28)
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 with the minimal two-file Rust example in the issue and reproduce the suggested “remove all the unused imports” assist. Locate the implementation and its unused-import analysis, then trace cross-file item-like usage such as crate::Foo; done means the assist is not offered when applying it would invalidate that usage, with a regression test for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100