Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
svix-jplatte opened this issue Nov 14, 2024 · 1 comment
Labels
A-assists A-nameres name, path and module resolution C-feature Category: feature request

Comments

@svix-jplatte
Copy link

  • 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)

@svix-jplatte svix-jplatte added the C-bug Category: bug label Nov 14, 2024
@flodiebold
Copy link
Member

I wouldn't see this as a bug, it's just how cfgs work -- the code simply doesn't exist if the feature isn't enabled.
Better handling for this would be quite hard to implement since the import statement isn't analyzed at all if the feature isn't active.

@flodiebold flodiebold added C-feature Category: feature request A-assists A-nameres name, path and module resolution and removed C-bug Category: bug labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists A-nameres name, path and module resolution C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

2 participants