rust-lang / rust-lang/rust

[ER] Better than the "unresolved import `super::K`" error message

Open
#140,449 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Code
For wrong code like this:


fn foo() {
    const K: usize = 1;

    mod inner {
        use super::K;

        fn bar() {
            dbg!(K);
        }
    }
}
fn main() {}
Current output
rustc 1.88.0-nightly (25cdf1f67 2025-04-28) currently gives:


error[E0432]: unresolved import `super::K`
 --> ...\test.rs:5:13
  |
5 |         use super::K;
  |             ^^^^^^^^ no `K` in the root

error: aborting due to 1 previous error
Desired output
But I'd like an error message that tries to suggest how to correctly import the name X.
Rationale and extra context

No response

Other cases

Rust Version
rustc 1.88.0-nightly (25cdf1f67 2025-04-28)
binary: rustc
commit-hash: 25cdf1f67463c9365d8d83778c933ec7480e940b
commit-date: 2025-04-28
host: x86_64-pc-windows-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
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.

Research direction

Reproduce the example with the reported rustc 1.88.0-nightly version and inspect how the unresolved import diagnostic is produced. Determine the correct import guidance for this nested-module case; done means the compiler suggests how to import the name rather than only reporting that super::K is unresolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.