rust-lang / rust-lang/rust-analyzer
import item quick-fix breaks `use` of macro that happens to share names with a module in the same scope
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer version: 0.3.1958-standalone
rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)
editor or extension: VSCode v0.3.1958
relevant settings:
{
"rust-analyzer.imports.prefix": "crate",
"rust-analyzer.imports.group.enable": false,
"rust-analyzer.cargo.targetDir": true,
}
repository link (if public, optional): (eg. rust-analyzer)
running the "import crate:🅱️:Baz2" quick-fix where indicated breaks the import of the some_mod macro, because rust-analyzer replaces the use with the following, which is incorrect because you can't import a macro using use path::to::macro::self:
use crate::{
a::some_mod::{self, Bar, Foo},
b::{Baz, Baz2},
};
code snippet to reproduce:
pub mod a {
pub mod some_mod {
#[derive(Hash)]
pub struct Foo;
#[derive(Hash)]
pub struct Bar;
}
pub use Hash as some_mod; // actually I have a attribute macro, but this should be sufficient for testing
}
pub mod b {
#[derive(Hash)]
pub struct Baz;
#[derive(Hash)]
pub struct Baz2;
}
pub mod c {
use crate::{
a::{
some_mod,
some_mod::{Foo, Bar},
},
b::Baz,
};
type T = Baz2; // use the "import crate::b::Baz2" quick-fix
#[derive(some_mod)]
pub struct S(Foo, Bar, Baz, T);
}
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 import crate::b::Baz2 quick-fix with the provided Rust snippet and inspect the import quick-fix handling. Verify that adding the import does not rewrite the macro import into some_mod::{self, ...} and that the resulting code still resolves some_mod, Foo, Bar, Baz, and Baz2.
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
- 35/100