about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-03-07 13:53:45 -0800
committerManish Goregaokar <manishsmail@gmail.com>2021-03-07 14:21:48 -0800
commitac7f9ccb6f84922d316a3efa2f50061d4af22801 (patch)
tree7280cb48a942d0b6beda79b431e84782b8767ec5
parent66ec64ccf31883cd2c28d045912a76179c0c6ed2 (diff)
diagnostics: Differentiate between edition meanings of ::foo in resolve diagnostics (for bare `::foo`)
-rw-r--r--compiler/rustc_resolve/src/lib.rs14
-rw-r--r--src/test/ui/editions-crate-root-2015.rs14
-rw-r--r--src/test/ui/editions-crate-root-2015.stderr15
-rw-r--r--src/test/ui/editions-crate-root-2018.rs14
-rw-r--r--src/test/ui/editions-crate-root-2018.stderr15
-rw-r--r--src/test/ui/editions/edition-imports-virtual-2015-gated.stderr2
-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
8 files changed, 72 insertions, 8 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index 7aee718bfa9..11b0ade1e83 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -2450,10 +2450,16 @@ impl<'a> Resolver<'a> {
                         }
                     } else {
                         let parent = path[i - 1].ident.name;
-                        let parent = if parent == kw::PathRoot {
-                            "crate root".to_owned()
-                        } else {
-                            format!("`{}`", parent)
+                        let parent = match parent {
+                            // ::foo is mounted at the crate root for 2015, and is the extern
+                            // prelude for 2018+
+                            kw::PathRoot if self.session.edition() > Edition::Edition2015 => {
+                                "the list of imported crates".to_owned()
+                            }
+                            kw::PathRoot | kw::Crate => "the crate root".to_owned(),
+                            _ => {
+                                format!("`{}`", parent)
+                            }
                         };
 
                         let mut msg = format!("could not find `{}` in {}", ident, parent);
diff --git a/src/test/ui/editions-crate-root-2015.rs b/src/test/ui/editions-crate-root-2015.rs
new file mode 100644
index 00000000000..71b7112804d
--- /dev/null
+++ b/src/test/ui/editions-crate-root-2015.rs
@@ -0,0 +1,14 @@
+// edition:2015
+
+mod inner {
+    fn global_inner(_: ::nonexistant::Foo) {
+        //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`?
+    }
+    fn crate_inner(_: crate::nonexistant::Foo) {
+        //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`?
+    }
+}
+
+fn main() {
+
+}
\ No newline at end of file
diff --git a/src/test/ui/editions-crate-root-2015.stderr b/src/test/ui/editions-crate-root-2015.stderr
new file mode 100644
index 00000000000..94c972227d0
--- /dev/null
+++ b/src/test/ui/editions-crate-root-2015.stderr
@@ -0,0 +1,15 @@
+error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
+  --> $DIR/editions-crate-root-2015.rs:4:26
+   |
+LL |     fn global_inner(_: ::nonexistant::Foo) {
+   |                          ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
+
+error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
+  --> $DIR/editions-crate-root-2015.rs:8:30
+   |
+LL |     fn crate_inner(_: crate::nonexistant::Foo) {
+   |                              ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0433`.
diff --git a/src/test/ui/editions-crate-root-2018.rs b/src/test/ui/editions-crate-root-2018.rs
new file mode 100644
index 00000000000..7e65f00920e
--- /dev/null
+++ b/src/test/ui/editions-crate-root-2018.rs
@@ -0,0 +1,14 @@
+// edition:2018
+
+mod inner {
+    fn global_inner(_: ::nonexistant::Foo) {
+        //~^ ERROR failed to resolve: could not find `nonexistant` in the list of imported crates
+    }
+    fn crate_inner(_: crate::nonexistant::Foo) {
+        //~^ ERROR failed to resolve: maybe a missing crate `nonexistant`?
+    }
+}
+
+fn main() {
+
+}
\ No newline at end of file
diff --git a/src/test/ui/editions-crate-root-2018.stderr b/src/test/ui/editions-crate-root-2018.stderr
new file mode 100644
index 00000000000..95a36907448
--- /dev/null
+++ b/src/test/ui/editions-crate-root-2018.stderr
@@ -0,0 +1,15 @@
+error[E0433]: failed to resolve: could not find `nonexistant` in the list of imported crates
+  --> $DIR/editions-crate-root-2018.rs:4:26
+   |
+LL |     fn global_inner(_: ::nonexistant::Foo) {
+   |                          ^^^^^^^^^^^ could not find `nonexistant` in the list of imported crates
+
+error[E0433]: failed to resolve: maybe a missing crate `nonexistant`?
+  --> $DIR/editions-crate-root-2018.rs:7:30
+   |
+LL |     fn crate_inner(_: crate::nonexistant::Foo) {
+   |                              ^^^^^^^^^^^ maybe a missing crate `nonexistant`?
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0433`.
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 06605c6f208..1cde0f72140 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 crate root
+   |     ^^^^^^^^^^^^^ could not find `E` in the list of imported crates
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
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 61212f299be..def60feb5a6 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 crate root
+    //~^ ERROR failed to resolve: could not find `xcrate` in the list of imported crates
 }
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 8b2a6933f37..7df4f06d1c7 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 crate root
+error[E0433]: failed to resolve: could not find `xcrate` in the list of imported crates
   --> $DIR/non-existent-2.rs:4:15
    |
 LL |     let s = ::xcrate::S;
-   |               ^^^^^^ could not find `xcrate` in crate root
+   |               ^^^^^^ could not find `xcrate` in the list of imported crates
 
 error: aborting due to previous error