Skip to content

Confusing diagnostics when forgetting to import rustc_abi crate #140840

Open
@RalfJung

Description

@RalfJung

Code

mod rs {
    pub use rustc_abi as abi;
}

fn foo(_x: rs::abi::Type) {}

Current output

error[E0433]: failed to resolve: could not find `abi` in `rs`
 --> src/lib.rs:5:16
  |
5 | fn foo(_x: rs::abi::Type) {}
  |                ^^^ could not find `abi` in `rs`

warning: unused import: `rustc_abi as abi`
 --> src/lib.rs:2:13
  |
2 |     pub use rustc_abi as abi;
  |             ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Desired output

It should point at `pub use rustc_abi as abi;` and complain that `rustc_abi` does not exist.

The correct fix is to add
extern crate rustc_abi;

Rationale and extra context

Neither of the actually shown errors is helpful:

  • One error says that rs::abi does not exist -- but clearly it does exist, I wrote it right there!
  • The other error says that rs::abi is unused -- but it is used, there's even an error pointing at it!

If I change rustc_abi to foobar, the error changes to something much better:

error[E0432]: unresolved import `foobar`
 --> src/lib.rs:2:13
  |
2 |     pub use foobar as abi;
  |             ^^^^^^^^^^^^^ no external crate `foobar`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` (lib) due to 1 previous error

I assume this is related to the fact that rustc_abi exists as a crate, it's just not been imported.

Other cases

Rust Version

Rust 1.86.0

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