rust-lang/rust-analyzer

auto-import sometimes breaks with `self` imports

Opened this issue ยท 9 comments

rust-analyzer version: 1.90.0 (1159e78 2025-09-14), 1.92.0-nightly (5c7ae0c 2025-10-02)

rustc version: 1.90.0 (1159e78c4 2025-09-14), 1.92.0-nightly (5c7ae0c 2025-10-02)

editor or extension: Zed

relevant settings: none, as far as I can tell

repository link: https://github.com/generic-daw/generic-daw

instructions to reproduce:

  1. clone above repo
  2. disable nightly-only features present in .rustfmt.toml (not strictly necessary, this reproduces without)
  3. navigate to https://github.com/generic-daw/generic-daw/blob/716331b78cec8fad10f8e09dbf92eb4ad76beae8/generic_daw_gui/src/arrangement_view.rs#L984
  4. remove the text:: prefix of text::Wrapping::None
  5. auto-import Wrapping from iced::widget::text::Wrapping
  6. observe that the import has been changed to text::{self, Wrapping}, and that all calls to the text function have broken

I'm sadly not sure how to minimize this, I've just encountered this specific case a bunch in this project and only just noticed that the aforementioned nightly-only rustfmt options aren't to blame.

Minimized Reproduction code:

use foo::bar;

mod foo {
    pub mod bar {
        pub enum Baz {
            BazVariant,
        }
    }

    pub fn bar() {}
}

fn main() {
    let t = bar::Baz::BazVariant;
    let b = bar();
}

TIL that you only need one import to refer the functions and module that are named the same.
I haven't tracked the one exact location, where the change needs to happen. But this code will surely help someone.

This probably needs to be fixed in a similar spot to #17494

I'll try to work on this because it makes iced development a big pain

I'll try to work on this because it makes iced development a big pain

@janTatesa I have been working on this on my free time. I have some progress after the discussion on Zulip #t-compiler/rust-analyzer > Opinions on how to fix this auto import bug

I can push my progress till now so you can have some reference if you want.

P.S: Sorry for not informing or claiming this issue ๐Ÿ˜…

I'll try to work on this because it makes iced development a big pain

@janTatesa I have been working on this on my free time. I have some progress after the discussion on Zulip #t-compiler/rust-analyzer > Opinions on how to fix this auto import bug

I can push my progress till now so you can have some reference if you want.

P.S: Sorry for not informing or claiming this issue ๐Ÿ˜…

Okay nevermind, I struggled with it anyways

I'll try to work on this because it makes iced development a big pain

@janTatesa I have been working on this on my free time. I have some progress after the discussion on Zulip #t-compiler/rust-analyzer > Opinions on how to fix this auto import bug
I can push my progress till now so you can have some reference if you want.
P.S: Sorry for not informing or claiming this issue ๐Ÿ˜…

Okay nevermind, I struggled with it anyways

It's not like I don't struggle as well :)

Anyways, here is my WIP branch if you want to reference: https://github.com/dfireBird/rust-analyzer/tree/merge_auto_import_fix

EDIT: My work on this will be pretty slow since I have juggle this with my day job. So if you want to work on this issue, go ahead.

After two weeks of trying to solution something that passes those tests (relatively closer at the very least). I can say I'm stuck at this point.

@janTatesa If you are still okay to do this, please take this up.

Well my paws are busy with other things rn, but when I'll have time I'll do

I also gave it a go last week, starting on your WIP branch, but I got stuck as well, while trying to understand how recursive_merge even works :/