rust-lang / rust-lang/rust-analyzer

Auto import unresolved module and constant value with similarly name

Open
#19,816 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: rust-analyzer 1.88.0-nightly (a15cce2 2025-04-17)

rustc version: rustc 1.88.0-nightly (a15cce269 2025-04-17)

editor or extension: VIM9.1 coc-rust-analyzer

code snippet to reproduce:

mod foo {
    pub mod bar {
        pub fn baz() {}
    }
    pub fn bar() {}
}
use foo::bar;

fn main() {
    let _ = bar();
    baz
}

On line 11 complete baz:

mod foo {
    pub mod bar {
        pub fn baz() {}
    }
    pub fn bar() {}
}
use foo::bar::{self, baz};

fn main() {
    let _ = bar();
    baz();
}

rustc: error[E0423]: expected function, found module `bar`

Expect:

mod foo {
    pub mod bar {
        pub fn baz() {}
    }
    pub fn bar() {}
}
use foo::{bar, bar::baz};

fn main() {
    let _ = bar();
    baz();
}

Clean reproduction of #10660

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

Start with the minimal Rust reproduction and the completion request for baz in the VIM9.1 coc-rust-analyzer example. Trace rust-analyzer's auto-import completion and name-resolution handling for a module and function sharing the name bar; done means the suggested import matches the expected use foo::{bar, bar::baz}; and compiles without E0423.

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.