about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_resolve/src/late.rs7
-rw-r--r--compiler/rustc_resolve/src/lib.rs14
-rw-r--r--src/test/ui/editions/edition-imports-virtual-2015-gated.stderr2
-rw-r--r--src/test/ui/resolve/crate-called-as-function.rs3
-rw-r--r--src/test/ui/resolve/crate-called-as-function.stderr9
-rw-r--r--src/test/ui/resolve/missing-in-namespace.rs4
-rw-r--r--src/test/ui/resolve/missing-in-namespace.stderr14
-rw-r--r--src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs2
-rw-r--r--src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr4
9 files changed, 51 insertions, 8 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 97e556f5a33..fff14747e57 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -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() {
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index af534162375..d293899dc0c 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -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() {
diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr
index 56cbd882cca..06605c6f208 100644
--- a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr
+++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr
@@ -2,7 +2,7 @@ error[E0432]: unresolved import `E`
   --> $DIR/edition-imports-virtual-2015-gated.rs:8:5
    |
 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)
 
diff --git a/src/test/ui/resolve/crate-called-as-function.rs b/src/test/ui/resolve/crate-called-as-function.rs
new file mode 100644
index 00000000000..e8f52c0c029
--- /dev/null
+++ b/src/test/ui/resolve/crate-called-as-function.rs
@@ -0,0 +1,3 @@
+fn main() {
+    ::foo() //~ cannot find external crate `foo` in the crate root
+}
diff --git a/src/test/ui/resolve/crate-called-as-function.stderr b/src/test/ui/resolve/crate-called-as-function.stderr
new file mode 100644
index 00000000000..eb42349aff1
--- /dev/null
+++ b/src/test/ui/resolve/crate-called-as-function.stderr
@@ -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`.
diff --git a/src/test/ui/resolve/missing-in-namespace.rs b/src/test/ui/resolve/missing-in-namespace.rs
new file mode 100644
index 00000000000..e1dedb072b7
--- /dev/null
+++ b/src/test/ui/resolve/missing-in-namespace.rs
@@ -0,0 +1,4 @@
+fn main() {
+    let _map = std::hahmap::HashMap::new();
+    //~^ ERROR failed to resolve: could not find `hahmap` in `std
+}
diff --git a/src/test/ui/resolve/missing-in-namespace.stderr b/src/test/ui/resolve/missing-in-namespace.stderr
new file mode 100644
index 00000000000..8b292aeda50
--- /dev/null
+++ b/src/test/ui/resolve/missing-in-namespace.stderr
@@ -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`.
diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs
index 4f53108b3a9..61212f299be 100644
--- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs
+++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.rs
@@ -2,5 +2,5 @@
 
 fn main() {
     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
 }
diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr
index 7395d01d8ac..8b2a6933f37 100644
--- a/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr
+++ b/src/test/ui/rfc-2126-extern-absolute-paths/non-existent-2.stderr
@@ -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
    |
 LL |     let s = ::xcrate::S;
-   |               ^^^^^^ could not find `xcrate` in `{{root}}`
+   |               ^^^^^^ could not find `xcrate` in crate root
 
 error: aborting due to previous error