Change:
Test program: This produces the following error messages: Both the error and the help seem entirely unhelpful. The error suggests that it looked for a function in the crate root, but in fact it looked for a crate . The whole "possible candidate" help seems incorrect, and adding that line would lead to a compilation failure.
cc
This is still an issue, but at least the incorrect help message is no longer displayed:

Discussion:
// "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 { <ins> // the case of `::some_crate()` ExprKind::Path(_, path) if path.segments.len() == 2 && path.segments[0].ident.name == kw::PathRoot => { "external crate" } </ins> ExprKind::Path(_, path) => { let mut msg = "function"; if let Some(segment) = path.segments.iter().last() {

(format!("use of undeclared crate or module `{}`", ident), None) } } else { <del> let mut msg = format!("could not find `{}` in `{}`", ident, path[i - 1].ident); </del> <ins> 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); </ins> if ns == TypeNS || ns == ValueNS { let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS }; if let FindBindingResult::Binding(Ok(binding)) =

{ let mut found = |what| { msg = format!( <del> "expected {}, found {} `{}` in `{}`", </del> <ins> "expected {}, found {} `{}` in {}", </ins> ns.descr(), what, ident, <del> path[i - 1].ident </del> <ins> parent </ins> ) }; if binding.module().is_some() {

--> $DIR/edition-imports-virtual-2015-gated.rs:8:5 | LL |     gen_gated!(); <del> |     ^^^^^^^^^^^^^ could not find `E` in `{{root}}` </del> <ins> |     ^^^^^^^^^^^^^ could not find `E` in crate root </ins> | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

<ins> fn main() { ::foo() //~ cannot find external crate `foo` in the crate root } </ins>

<ins> 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`. </ins>

<ins> fn main() { let _map = std::hahmap::HashMap::new(); //~^ ERROR failed to resolve: could not find `hahmap` in `std } </ins>

<ins> 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`. </ins>

fn main() { let s = ::xcrate::S; <del> //~^ ERROR failed to resolve: could not find `xcrate` in `{{root}}` </del> <ins> //~^ ERROR failed to resolve: could not find `xcrate` in crate root </ins> }

<del> error[E0433]: failed to resolve: could not find `xcrate` in `{{root}}` </del> <ins> error[E0433]: failed to resolve: could not find `xcrate` in crate root </ins> --> $DIR/non-existent-2.rs:4:15 | LL |     let s = ::xcrate::S; <del> |               ^^^^^^ could not find `xcrate` in `{{root}}` </del> <ins> |               ^^^^^^ could not find `xcrate` in crate root </ins> error: aborting due to previous error