Skip to content

Misleading use foo::bar error message #61942

Open
@brson

Description

@brson

Here are two slightly different sources with slightly different errors:

use foo;

fn main() { }
error[E0432]: unresolved import `foo`
 --> src/main.rs:1:5
  |
1 | use foo;
  |     ^^^ no `foo` external crate
use foo::bar;

fn main() { }
error[E0432]: unresolved import `foo`
 --> src/main.rs:1:5
  |
1 | use foo::bar;
  |     ^^^ use of undeclared type or module `foo`

For use foo, the error is "no foo external crate"; for use foo::bar it is "undeclared type or module foo".

The first error I think is unambiguously correct - there's nothing foo could be but an external crate. The second though is failing to mention that foo could very will be a missing crate. And it may be more likely to be a missing crate (or a typo...) than a type or module that hasn't been imported.

I encountered this second error while writing some training material and had to explain that the error is misleading and that actually you need to list crate foo in your manifest.

A better error might be "use of undeclared crate, type, or module" (while also changing the first one to "use of undeclared crate" for consistency), or "no foo extern crate, or use of undeclared type or module foo". Even better might be to do some analysis to see if there is any crate with a name close to "foo", whether there are any internal names equal to or similar to "foo", and customize the error based on that.

This is using whatever nightly is current right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-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