rust-lang / rust-lang/rust-analyzer

Ambiguous module files report unrelated errors

Open
#23,372 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When there is a module name collision, rust-analyzer reports unrelated errors making it hard for the user to understand what is going on. I believe this is what we see on #19709.

A reproducible test case is available in https://github.com/stephanemagnenat/ra-ghost-module, the related Zed issue that surfaced this situation in the first place is reported here: zed-industries/zed#64231.

It could be good if rust-analyzer would report a clear user message like the Rust compiler do:

error[E0761]: file for module `ast` found at both "src/ast.rs" and "src/ast/mod.rs"
   --> src/lib.rs:1:1
    |
  1 | mod ast;
    | ^^^^^^^^
    |
    = help: delete or rename one of them to remove the ambiguity

instead of the current behaviour when errors related to common std types appear instead.

This issue is a follow up of issue #23366 but focusing on the error message reporting, which is the real problem here.

rust-analyzer version: 0.3.3049-standalone (release 2026-09-14, commit https://github.com/rust-lang/rust-analyzer/commit/682a84e95b5a52cf06e9822fcaa4f628738554bf)
rustc version: 1.98.0 (88d9e12ae 2026-08-18)
editor or extension: Zed 1.19.2 (df181c6f58d0)

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 by reproducing the module collision with the case in https://github.com/stephanemagnenat/ra-ghost-module and compare rust-analyzer's diagnostics with the Rust compiler's E0761 output. Trace the diagnostic entry point for the ambiguous module and make the reported message identify both conflicting paths and the module declaration; verify the unrelated std-type errors are replaced by the clear ambiguity diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.