rust-lang / rust-lang/rust-analyzer
Unknown symbol import assist, if it finds a renamed import, imports the original name instead
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: 0.3.1868-standalone (037924c4d 2024-03-03)
rustc version: rustc 1.76.0 (07dca489a 2024-02-04)
code snippet to reproduce:
use std::io::Result as IoResult;
mod foo {
pub fn bar() -> IoResult<()> {
Ok(())
}
}
This code produces the error “cannot find type IoResult in this scope”. Put the cursor on the IoResult and try to fix it using rust-analyzer assists.
- What should happen: add
use crate::IoResult;, or qualify ascrate::IoResult. - What actually happens: add
use std::io::Result;, which doesn't fix the error, or qualify asstd::io::Result, which compiles but isn't appropriate (in the actual case I met this problem, the name iscfged to be one of two possible types).
Also, rustc provides a correct suggestion here, but there's no obvious way to apply it.
Arguably, for this purpose I should be using a type alias instead of use (which RA handles correctly), but there is clearly a bug at least in the case of importing rather than qualifying.
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
Reproduce the issue with the Rust snippet and the unknown-symbol import assist, then trace how the assist resolves renamed imports. Done means the import or qualification preserves the visible alias and fixes the unresolved name, with a regression test covering this case.
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
- 38/100