about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev+love@gmail.com>2023-01-10 08:05:34 +0900
committerGitHub <noreply@github.com>2023-01-10 08:05:34 +0900
commit684a3717cb78ef8a8c3182b0b2ef630dadb7c4aa (patch)
treec4d8e34ecdfb95eafa1a9f4b09611e03f1090caf /src/test
parent5773e8baf017956849f821d5c85837ca1162b4ae (diff)
parent1d66a675bb61c21555dcb848ed7378b6f2848de7 (diff)
Rollup merge of #106175 - compiler-errors:bad-import-sugg, r=oli-obk
Fix bad import suggestion with nested `use` tree

Fixes #105566
Fixes #105373

Ideally, we'd find some way to turn these into structured suggestions -- perhaps on a separate line as a different `use` statement, but I have no idea how to access the span for the whole `use` from this point in the import resolution code.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr5
-rw-r--r--src/test/ui/imports/bad-import-in-nested.rs27
-rw-r--r--src/test/ui/imports/bad-import-in-nested.stderr30
-rw-r--r--src/test/ui/imports/bad-import-with-rename.rs16
-rw-r--r--src/test/ui/imports/bad-import-with-rename.stderr25
-rw-r--r--src/test/ui/test-attrs/inaccessible-test-modules.stderr13
6 files changed, 102 insertions, 14 deletions
diff --git a/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr b/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr
index e89c19b5881..f1f4caee361 100644
--- a/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr
+++ b/src/test/ui/hygiene/extern-prelude-from-opaque-fail.stderr
@@ -2,10 +2,7 @@ error[E0432]: unresolved import `my_core`
   --> $DIR/extern-prelude-from-opaque-fail.rs:20:9
    |
 LL |     use my_core;
-   |         ^^^^^^^
-   |         |
-   |         no `my_core` in the root
-   |         help: a similar name exists in the module: `my_core`
+   |         ^^^^^^^ no `my_core` in the root
 
 error[E0432]: unresolved import `my_core`
   --> $DIR/extern-prelude-from-opaque-fail.rs:7:13
diff --git a/src/test/ui/imports/bad-import-in-nested.rs b/src/test/ui/imports/bad-import-in-nested.rs
new file mode 100644
index 00000000000..2e95480ad41
--- /dev/null
+++ b/src/test/ui/imports/bad-import-in-nested.rs
@@ -0,0 +1,27 @@
+// edition: 2021
+
+#![allow(unused)]
+
+mod A {
+    pub(crate) type AA = ();
+    pub(crate) type BB = ();
+
+    mod A2 {
+        use super::{super::C::D::AA, AA as _};
+        //~^ ERROR unresolved import
+    }
+}
+
+mod C {
+    pub mod D {}
+}
+
+mod B {
+    use crate::C::{self, AA};
+    //~^ ERROR unresolved import
+
+    use crate::{A, C::BB};
+    //~^ ERROR unresolved import
+}
+
+fn main() {}
diff --git a/src/test/ui/imports/bad-import-in-nested.stderr b/src/test/ui/imports/bad-import-in-nested.stderr
new file mode 100644
index 00000000000..855b1e637e9
--- /dev/null
+++ b/src/test/ui/imports/bad-import-in-nested.stderr
@@ -0,0 +1,30 @@
+error[E0432]: unresolved import `super::super::C::D::AA`
+  --> $DIR/bad-import-in-nested.rs:10:21
+   |
+LL |         use super::{super::C::D::AA, AA as _};
+   |                     ^^^^^^^^^^^^^^^ no `AA` in `C::D`
+   |
+   = note: consider importing this type alias instead:
+           crate::A::AA
+
+error[E0432]: unresolved import `crate::C::AA`
+  --> $DIR/bad-import-in-nested.rs:20:26
+   |
+LL |     use crate::C::{self, AA};
+   |                          ^^ no `AA` in `C`
+   |
+   = note: consider importing this type alias instead:
+           crate::A::AA
+
+error[E0432]: unresolved import `crate::C::BB`
+  --> $DIR/bad-import-in-nested.rs:23:20
+   |
+LL |     use crate::{A, C::BB};
+   |                    ^^^^^ no `BB` in `C`
+   |
+   = note: consider importing this type alias instead:
+           crate::A::BB
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0432`.
diff --git a/src/test/ui/imports/bad-import-with-rename.rs b/src/test/ui/imports/bad-import-with-rename.rs
new file mode 100644
index 00000000000..ffe56916f92
--- /dev/null
+++ b/src/test/ui/imports/bad-import-with-rename.rs
@@ -0,0 +1,16 @@
+mod A {
+    pub type B = ();
+    pub type B2 = ();
+}
+
+mod C {
+    use crate::D::B as _;
+    //~^ ERROR unresolved import `crate::D::B`
+
+    use crate::D::B2;
+    //~^ ERROR unresolved import `crate::D::B2`
+}
+
+mod D {}
+
+fn main() {}
diff --git a/src/test/ui/imports/bad-import-with-rename.stderr b/src/test/ui/imports/bad-import-with-rename.stderr
new file mode 100644
index 00000000000..cace2a7a51c
--- /dev/null
+++ b/src/test/ui/imports/bad-import-with-rename.stderr
@@ -0,0 +1,25 @@
+error[E0432]: unresolved import `crate::D::B`
+  --> $DIR/bad-import-with-rename.rs:7:9
+   |
+LL |     use crate::D::B as _;
+   |         ^^^^^^^^^^^^^^^^ no `B` in `D`
+   |
+help: consider importing this type alias instead
+   |
+LL |     use A::B as _;
+   |         ~~~~~~~~~~
+
+error[E0432]: unresolved import `crate::D::B2`
+  --> $DIR/bad-import-with-rename.rs:10:9
+   |
+LL |     use crate::D::B2;
+   |         ^^^^^^^^^^^^ no `B2` in `D`
+   |
+help: consider importing this type alias instead
+   |
+LL |     use A::B2;
+   |         ~~~~~~
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0432`.
diff --git a/src/test/ui/test-attrs/inaccessible-test-modules.stderr b/src/test/ui/test-attrs/inaccessible-test-modules.stderr
index 0c16ecd4c86..a45c5bd4588 100644
--- a/src/test/ui/test-attrs/inaccessible-test-modules.stderr
+++ b/src/test/ui/test-attrs/inaccessible-test-modules.stderr
@@ -2,10 +2,7 @@ error[E0432]: unresolved import `main`
   --> $DIR/inaccessible-test-modules.rs:5:5
    |
 LL | use main as x;
-   |     ----^^^^^
-   |     |
-   |     no `main` in the root
-   |     help: a similar name exists in the module: `main`
+   |     ^^^^^^^^^ no `main` in the root
 
 error[E0432]: unresolved import `test`
   --> $DIR/inaccessible-test-modules.rs:6:5
@@ -13,14 +10,10 @@ error[E0432]: unresolved import `test`
 LL | use test as y;
    |     ^^^^^^^^^ no `test` in the root
    |
-help: a similar name exists in the module
-   |
-LL | use test as y;
-   |     ~~~~
 help: consider importing this module instead
    |
-LL | use test::test;
-   |     ~~~~~~~~~~~
+LL | use test::test as y;
+   |     ~~~~~~~~~~~~~~~~
 
 error: aborting due to 2 previous errors