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.
This commit is contained in:
Tyler Mandry 2020-09-09 15:05:45 -07:00 committed by GitHub
commit 5ea55518bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 126 additions and 105 deletions

View file

@ -2413,7 +2413,14 @@ impl<'a> Resolver<'a> {
(format!("maybe a missing crate `{}`?", ident), None)
}
} else if i == 0 {
(format!("use of undeclared type or module `{}`", ident), None)
if ident
.name
.with(|n| n.chars().next().map_or(false, |c| c.is_ascii_uppercase()))
{
(format!("use of undeclared type `{}`", ident), None)
} else {
(format!("use of undeclared crate or module `{}`", ident), None)
}
} else {
let mut msg =
format!("could not find `{}` in `{}`", ident, path[i - 1].ident);