Skip to content

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

Open
@leonardo-m

Description

@leonardo-m

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions