Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading use foo::bar error message #61942

Open
brson opened this issue Jun 18, 2019 · 3 comments
Open

Misleading use foo::bar error message #61942

brson opened this issue Jun 18, 2019 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@brson
Copy link
Contributor

brson commented Jun 18, 2019

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.

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jun 18, 2019
@Centril
Copy link
Contributor

Centril commented Jun 18, 2019

cc @estebank @petrochenkov

@Centril Centril added the A-resolve Area: Path resolution label Jun 18, 2019
@petrochenkov
Copy link
Contributor

The amount and inconsistency of resolve diagnostics make it hard to update them synchronously with the language.
In the uniform path PR I made sure diagnostics do not regress, but didn't update diagnostics that didn't change, and I didn't touch them since then.

@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 7, 2019
@Spoonbender
Copy link

Triage: no change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants