Confusing diagnostics when forgetting to import `rustc_abi` crate
Open
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
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::abidoes not exist -- but clearly it does exist, I wrote it right there! - The other error says that
rs::abiis 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Rust 1.86.0 example and compare the diagnostics for rustc_abi and foobar. Investigate the compiler's unresolved-import and name-resolution diagnostic paths; done means the error points to pub use rustc_abi as abi; and reports that rustc_abi must be imported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100