rust-lang / rust-lang/rust-analyzer
Import defaults to unexpected `use`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
In Pyrefly (https://github.com/facebook/pyrefly) we have a library which defines types (e.g. crate::config::config::ConfigFile) and then exports a subset of those types to a binary (e.g. pub use in the root). What is exported changes based on our needs, and it is not a stable library interface. Within the library, we'd prefer to always use the real definition of the type, and not the exported version. But Rust Analyzer always seems to prefer the exported version, so used to insert use create::ConfigFile by preference. We moved these into a mod exported to try and discourage Rust Analyzer, and make it easier to see when that happened, but Rust Analyzer now prefers the use crate::exported::ConfigFile instead of the real location.
Is there any way to predict/control which import RA will use?
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 import choice using the Pyrefly examples in pyrefly/lib/config/config.rs and the exports in pyrefly/lib/lib.rs around lines 54-74. Then trace Rust Analyzer's import-selection behavior and determine whether the choice can be predicted or controlled; done means documenting the behavior or identifying a concrete control.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100