-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Error messages about modules are confusing to beginners #50701
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
When a beginner [0] first tries to use modules, they are likely to do it wrong. The error message printed is misleading because it only mentions
extern crate fooand never mentionsExample
Consider the following project:
src/main.rs:
src/foo.rs:
Running
cargo runresults in the following error message:Naturally, one might try adding
extern crate foo;to the top of main.rs. This changes the error message to:If a user reads the output of
rustc --explain E0432, they might instead try changing main.rs to start withuse self::foo::say_hello;, though this does not change the error message.Another common thing to try is adding
mod foo;orpub mod foo;to the top offoo.rs. It is very unlikely that a user will stumble upon an actual solution (such as addingmod foo;to the top ofmain.rs).Suggestion
The error message should also mention how to refer to local modules, not just external crates.
If there is a file that matches the module name the user is trying to import, it would be especially helpful if the error message discussed how to correctly use that module from
main.rs.Meta
[0] or myself, after having not touched Rust in over a year