about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2021-09-29 13:55:24 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2021-10-13 12:17:02 +0900
commitf819e6d59c41b6bb3db2810c5c8e340b2fb2a88d (patch)
tree574e3ecd2b8c3aa878307061db9de08289d8281e /src/test
parentd7539a6af09e5889ed9bcb8b49571b7a59c32e65 (diff)
downloadrust-f819e6d59c41b6bb3db2810c5c8e340b2fb2a88d.tar.gz
rust-f819e6d59c41b6bb3db2810c5c8e340b2fb2a88d.zip
suggestion for typoed crate or module
avoid suggesting the same name

sort candidates

fix a message

use `opt_def_id` instead of `def_id`

move `find_similarly_named_module_or_crate` to rustc_resolve/src/diagnostics.rs
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/macros/macro-inner-attributes.stderr5
-rw-r--r--src/test/ui/suggestions/crate-or-module-typo.rs17
-rw-r--r--src/test/ui/suggestions/crate-or-module-typo.stderr43
3 files changed, 65 insertions, 0 deletions
diff --git a/src/test/ui/macros/macro-inner-attributes.stderr b/src/test/ui/macros/macro-inner-attributes.stderr
index 8223220d9a4..77b6486155c 100644
--- a/src/test/ui/macros/macro-inner-attributes.stderr
+++ b/src/test/ui/macros/macro-inner-attributes.stderr
@@ -3,6 +3,11 @@ error[E0433]: failed to resolve: use of undeclared crate or module `a`
    |
 LL |     a::bar();
    |     ^ use of undeclared crate or module `a`
+   |
+help: there is a crate or module with a similar name
+   |
+LL |     b::bar();
+   |     ~
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/suggestions/crate-or-module-typo.rs b/src/test/ui/suggestions/crate-or-module-typo.rs
new file mode 100644
index 00000000000..2471b11c61e
--- /dev/null
+++ b/src/test/ui/suggestions/crate-or-module-typo.rs
@@ -0,0 +1,17 @@
+// edition:2018
+
+use st::cell::Cell; //~ ERROR failed to resolve: use of undeclared crate or module `st`
+
+mod bar {
+    pub fn bar() { bar::baz(); } //~ ERROR failed to resolve: use of undeclared crate or module `bar`
+
+    fn baz() {}
+}
+
+use bas::bar; //~ ERROR unresolved import `bas`
+
+struct Foo {
+    bar: st::cell::Cell<bool> //~ ERROR failed to resolve: use of undeclared crate or module `st`
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/crate-or-module-typo.stderr b/src/test/ui/suggestions/crate-or-module-typo.stderr
new file mode 100644
index 00000000000..e8250c9fa5f
--- /dev/null
+++ b/src/test/ui/suggestions/crate-or-module-typo.stderr
@@ -0,0 +1,43 @@
+error[E0433]: failed to resolve: use of undeclared crate or module `st`
+  --> $DIR/crate-or-module-typo.rs:3:5
+   |
+LL | use st::cell::Cell;
+   |     ^^ use of undeclared crate or module `st`
+   |
+help: there is a crate or module with a similar name
+   |
+LL | use std::cell::Cell;
+   |     ~~~
+
+error[E0432]: unresolved import `bas`
+  --> $DIR/crate-or-module-typo.rs:11:5
+   |
+LL | use bas::bar;
+   |     ^^^ use of undeclared crate or module `bas`
+   |
+help: there is a crate or module with a similar name
+   |
+LL | use bar::bar;
+   |     ~~~
+
+error[E0433]: failed to resolve: use of undeclared crate or module `bar`
+  --> $DIR/crate-or-module-typo.rs:6:20
+   |
+LL |     pub fn bar() { bar::baz(); }
+   |                    ^^^ use of undeclared crate or module `bar`
+
+error[E0433]: failed to resolve: use of undeclared crate or module `st`
+  --> $DIR/crate-or-module-typo.rs:14:10
+   |
+LL |     bar: st::cell::Cell<bool>
+   |          ^^ use of undeclared crate or module `st`
+   |
+help: there is a crate or module with a similar name
+   |
+LL |     bar: std::cell::Cell<bool>
+   |          ~~~
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0432, E0433.
+For more information about an error, try `rustc --explain E0432`.