rust-lang / rust-lang/rust-analyzer

Auto-import of an item that's already conditionally-imported creates a duplicate import

Open
#18,509 1 comment 0 reactions 0 assignees View on GitHub

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 foo being 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.