rust-lang / rust-lang/rust-analyzer
Block specific items from being auto-imported
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
There are some crate providing items with same names as well-known items from std. If the item from the crate is not an alias of the one from std, importing it causes errors. Most of the time, the errors are confusing, as it is really unusual, unless the crates' user has encountered it before.
For example, anyhow::Ok conflicts with std::result::Result::Ok, and unlike the std one as an enum variant, it is a function. If I type ok in the editor and adopt the first candidate without checking the completion list carefully, anyhow::Ok will be imported, breaking other Oks (e.g. the Ok in match patterns).
In my opinion, most of the time when using auto-import, well-known items like std::result::Result::Ok should be always picked unless the other ones are specified purposely or already imported. It is not ergonomic to require developers to check such items carefully every times they use auto-import.
However, identifying which item is "well-known" seems to exceed the capabilities rust-analyzer should have. It is also not always possible to persuade the crates' maintainer to remove such footguns. As an alternative, rust-analyzer could be able to be configured to block specified items being auto-imported.
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
No files or tests are named. Start by tracing rust-analyzer's auto-import candidate selection and configuration handling, using the anyhow::Ok versus std::result::Result::Ok example as the behavioral case; done means users can configure specific items that auto-import must skip without preventing intentional imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100