Improve unknown external crate error
This commit is contained in:
parent
4e208f6a3a
commit
d829e40c7b
|
@ -244,6 +244,13 @@ impl<'a> PathSource<'a> {
|
||||||
// "function" here means "anything callable" rather than `DefKind::Fn`,
|
// "function" here means "anything callable" rather than `DefKind::Fn`,
|
||||||
// this is not precise but usually more helpful than just "value".
|
// this is not precise but usually more helpful than just "value".
|
||||||
Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {
|
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) => {
|
ExprKind::Path(_, path) => {
|
||||||
let mut msg = "function";
|
let mut msg = "function";
|
||||||
if let Some(segment) = path.segments.iter().last() {
|
if let Some(segment) = path.segments.iter().last() {
|
||||||
|
|
|
@ -2458,8 +2458,14 @@ impl<'a> Resolver<'a> {
|
||||||
(format!("use of undeclared crate or module `{}`", ident), None)
|
(format!("use of undeclared crate or module `{}`", ident), None)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut msg =
|
let parent = path[i - 1].ident.name;
|
||||||
format!("could not find `{}` in `{}`", ident, path[i - 1].ident);
|
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 {
|
if ns == TypeNS || ns == ValueNS {
|
||||||
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
|
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
|
||||||
if let FindBindingResult::Binding(Ok(binding)) =
|
if let FindBindingResult::Binding(Ok(binding)) =
|
||||||
|
@ -2467,11 +2473,11 @@ impl<'a> Resolver<'a> {
|
||||||
{
|
{
|
||||||
let mut found = |what| {
|
let mut found = |what| {
|
||||||
msg = format!(
|
msg = format!(
|
||||||
"expected {}, found {} `{}` in `{}`",
|
"expected {}, found {} `{}` in {}",
|
||||||
ns.descr(),
|
ns.descr(),
|
||||||
what,
|
what,
|
||||||
ident,
|
ident,
|
||||||
path[i - 1].ident
|
parent
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if binding.module().is_some() {
|
if binding.module().is_some() {
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0432]: unresolved import `E`
|
||||||
--> $DIR/edition-imports-virtual-2015-gated.rs:8:5
|
--> $DIR/edition-imports-virtual-2015-gated.rs:8:5
|
||||||
|
|
|
|
||||||
LL | gen_gated!();
|
LL | gen_gated!();
|
||||||
| ^^^^^^^^^^^^^ could not find `E` in `{{root}}`
|
| ^^^^^^^^^^^^^ could not find `E` in crate root
|
||||||
|
|
|
|
||||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s = ::xcrate::S;
|
let s = ::xcrate::S;
|
||||||
//~^ ERROR failed to resolve: could not find `xcrate` in `{{root}}`
|
//~^ ERROR failed to resolve: could not find `xcrate` in crate root
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0433]: failed to resolve: could not find `xcrate` in `{{root}}`
|
error[E0433]: failed to resolve: could not find `xcrate` in crate root
|
||||||
--> $DIR/non-existent-2.rs:4:15
|
--> $DIR/non-existent-2.rs:4:15
|
||||||
|
|
|
|
||||||
LL | let s = ::xcrate::S;
|
LL | let s = ::xcrate::S;
|
||||||
| ^^^^^^ could not find `xcrate` in `{{root}}`
|
| ^^^^^^ could not find `xcrate` in crate root
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue