rust-lang / rust-lang/rust-analyzer
Auto-import of an item that's already conditionally-imported creates a duplicate import
Open
Nobody has claimed this yet.
A-assists
A-nameres
C-feature
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
- given an input like
#[cfg(feature = "foo")] use std::collections::HashMap; fn bar() -> HashMap { todo!() } - with
foobeing an inactive feature cfg in the current RA session - when using the import assist on
HashMap - a second
use std::collections::HashMap;is generated - which will result in a duplicate import error when the code is compiled with
--feature foo
rust-analyzer version: 0.4.2183-standalone
rustc version: 1.84.0-nightly (b8c8287a2 2024-11-03)
editor or extension: VSCode w/ RA v0.4.2183 (pre-release)
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-assist case in a Rust file using the conditional HashMap import and an inactive feature cfg. Start at the import assist entry point and trace how existing conditional imports are considered; done means invoking the assist does not generate a duplicate import and the example compiles when feature foo is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100