-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve unknown external crate error #81046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2458,20 +2458,26 @@ 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, the path root is normally referred to as the crate root as you can see here. |
||
} else { | ||
format!("`{}`", parent) | ||
estebank marked this conversation as resolved.
Show resolved
Hide resolved
rylev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
Comment on lines
+2462
to
+2466
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than special casing this here, does it make sense to change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is certainly a possibility. I didn't do this because I was unsure of the ramifications of renaming the symbol's string representation (particularly around json serialization/deserialization). The change I made seems to be the central place for diagnostics around path resolution (i.e., there are not UI tests that still reference |
||
|
||
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)) = | ||
find_binding_in_ns(self, ns_to_try) | ||
{ | ||
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() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
::foo() //~ cannot find external crate `foo` in the crate root | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0425]: cannot find external crate `foo` in the crate root | ||
--> $DIR/crate-called-as-function.rs:2:7 | ||
| | ||
LL | ::foo() | ||
| ^^^ not found in the crate root | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let _map = std::hahmap::HashMap::new(); | ||
//~^ ERROR failed to resolve: could not find `hahmap` in `std | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0433]: failed to resolve: could not find `hahmap` in `std` | ||
--> $DIR/missing-in-namespace.rs:2:29 | ||
| | ||
LL | let _map = std::hahmap::HashMap::new(); | ||
| ^^^^^^^ not found in `std::hahmap` | ||
| | ||
help: consider importing this struct | ||
| | ||
LL | use std::collections::HashMap; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0433`. |
Uh oh!
There was an error while loading. Please reload this page.