Rollup merge of #81046 - rylev:unknown-external-crate, r=estebank
Improve unknown external crate error This improves error messages when unknown items in the crate root are encountered. Fixes #63799 r? ```@estebank```
This commit is contained in:
commit
a77c1d836a
9 changed files with 51 additions and 8 deletions
|
@ -243,6 +243,13 @@ impl<'a> PathSource<'a> {
|
|||
// "function" here means "anything callable" rather than `DefKind::Fn`,
|
||||
// this is not precise but usually more helpful than just "value".
|
||||
Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {
|
||||
// the case of `::some_crate()`
|
||||
ExprKind::Path(_, path)
|
||||
if path.segments.len() == 2
|
||||
&& path.segments[0].ident.name == kw::PathRoot =>
|
||||
{
|
||||
"external crate"
|
||||
}
|
||||
ExprKind::Path(_, path) => {
|
||||
let mut msg = "function";
|
||||
if let Some(segment) = path.segments.iter().last() {
|
||||
|
|
|
@ -2485,8 +2485,14 @@ impl<'a> Resolver<'a> {
|
|||
(format!("use of undeclared crate or module `{}`", ident), None)
|
||||
}
|
||||
} else {
|
||||
let mut msg =
|
||||
format!("could not find `{}` in `{}`", ident, path[i - 1].ident);
|
||||
let parent = path[i - 1].ident.name;
|
||||
let parent = if parent == kw::PathRoot {
|
||||
"crate root".to_owned()
|
||||
} else {
|
||||
format!("`{}`", parent)
|
||||
};
|
||||
|
||||
let mut msg = format!("could not find `{}` in {}", ident, parent);
|
||||
if ns == TypeNS || ns == ValueNS {
|
||||
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
|
||||
if let FindBindingResult::Binding(Ok(binding)) =
|
||||
|
@ -2494,11 +2500,11 @@ impl<'a> Resolver<'a> {
|
|||
{
|
||||
let mut found = |what| {
|
||||
msg = format!(
|
||||
"expected {}, found {} `{}` in `{}`",
|
||||
"expected {}, found {} `{}` in {}",
|
||||
ns.descr(),
|
||||
what,
|
||||
ident,
|
||||
path[i - 1].ident
|
||||
parent
|
||||
)
|
||||
};
|
||||
if binding.module().is_some() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue