rust-lang / rust-lang/rust

Too many errors for missing crate for nested imports and later uses of crate

Open
#153,156 1 comment 0 reactions 1 assignee View on GitHub

@yuk1ty is already working on this.

Since Mar 14, 2026.

A-diagnostics D-verbose T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
use foo::{bar, baz::bat};
pub fn main() {
    foo::qux();
}
Current output
error[E0433]: cannot find module or crate `foo` in this scope
 --> src/main.rs:1:5
  |
1 | use foo::{bar, baz::bat};
  |     ^^^ use of unresolved module or unlinked crate `foo`
  |
  = help: if you wanted to use a crate named `foo`, use `cargo add foo` to add it to your `Cargo.toml`

error[E0432]: unresolved import `foo`
 --> src/main.rs:1:5
  |
1 | use foo::{bar, baz::bat};
  |     ^^^ use of unresolved module or unlinked crate `foo`
  |
  = help: if you wanted to use a crate named `foo`, use `cargo add foo` to add it to your `Cargo.toml`

error[E0433]: cannot find module or crate `foo` in this scope
 --> src/main.rs:3:5
  |
3 |     foo::qux();
  |     ^^^ use of unresolved module or unlinked crate `foo`
  |
  = help: if you wanted to use a crate named `foo`, use `cargo add foo` to add it to your `Cargo.toml`
Desired output
error[E0432]: unresolved import `foo`
 --> src/main.rs:1:5
  |
1 | use foo::{bar, baz::bat};
  |     ^^^ use of unresolved module or unlinked crate `foo`
  |
  = help: if you wanted to use a crate named `foo`, use `cargo add foo` to add it to your `Cargo.toml`
Rationale and extra context

Either one of the first two errors would be fine, both at the same time are redundant.

The third error is more acceptable, but ideally we wouldn't emit it. Potentially, it might make sense to have a single error pointing at line 1 and line 3, but we can "just" silence the third error after the prior import error (like we already do if we write use foo;). This would make it so that a fixing a typo in the import would then suddenly trigger later errors in places where the typo also needed to be fixed, but that should be ok.

Other cases

Rust Version
1.93 and 1.95 nightly
Anything else?

No response

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.