about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2020-09-09 15:05:45 -0700
committerGitHub <noreply@github.com>2020-09-09 15:05:45 -0700
commit5ea55518bcd168517d7e5b526e94e0d09470cb11 (patch)
tree70929ada84a46d1f37df6d1b0eb817cda91d3f12 /compiler/rustc_error_codes/src
parent07dbe49ce9239c5caefe8556566cab0b36c60faf (diff)
parent7ec1de062a1aadef0293bb65e71fbcc7cc24ebfd (diff)
downloadrust-5ea55518bcd168517d7e5b526e94e0d09470cb11.tar.gz
rust-5ea55518bcd168517d7e5b526e94e0d09470cb11.zip
Rollup merge of #75984 - kornelski:typeormodule, r=matthewjasper
Improve unresolved use error message

"use of undeclared type or module `foo`" doesn't mention that it could be a crate.

This error can happen when users forget to add a dependency to `Cargo.toml`, so I think it's important to mention that it could be a missing crate.

I've used a heuristic based on Rust's naming conventions. It complains about an unknown type if the ident starts with an upper-case letter, and crate or module otherwise. It seems to work very well. The expanded error help covers both an unknown type and a missing crate case.
Diffstat (limited to 'compiler/rustc_error_codes/src')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0433.md16
1 files changed, 13 insertions, 3 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0433.md b/compiler/rustc_error_codes/src/error_codes/E0433.md
index f9e333e8ccd..5a64c13c9af 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0433.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0433.md
@@ -1,17 +1,27 @@
-An undeclared type or module was used.
+An undeclared crate, module, or type was used.
 
 Erroneous code example:
 
 ```compile_fail,E0433
 let map = HashMap::new();
-// error: failed to resolve: use of undeclared type or module `HashMap`
+// error: failed to resolve: use of undeclared type `HashMap`
 ```
 
 Please verify you didn't misspell the type/module's name or that you didn't
 forget to import it:
 
-
 ```
 use std::collections::HashMap; // HashMap has been imported.
 let map: HashMap<u32, u32> = HashMap::new(); // So it can be used!
 ```
+
+If you've expected to use a crate name:
+
+```compile_fail
+use ferris_wheel::BigO;
+// error: failed to resolve: use of undeclared crate or module `ferris_wheel`
+```
+
+Make sure the crate has been added as a dependency in `Cargo.toml`.
+
+To use a module from your current crate, add the `crate::` prefix to the path.