about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-27 22:13:02 +0200
committerGitHub <noreply@github.com>2025-06-27 22:13:02 +0200
commit190a1a7f747408d1936a81065665c687013f6141 (patch)
tree8323759b9e16757fae6d36e92f0d54db355e121c /tests/ui
parent9d15167921ead28946d8d603470dbe9a57e74eff (diff)
parent57cb419cc5c57afb2456d9e4af0e722a5b9324b9 (diff)
downloadrust-190a1a7f747408d1936a81065665c687013f6141.tar.gz
rust-190a1a7f747408d1936a81065665c687013f6141.zip
Rollup merge of #142730 - bend-n:suggest_declaring_modules_when_file_found_but_module_not_defined, r=petrochenkov
suggest declaring modules when file found but module not defined

suggests declaring modules when a module is found but not defined, i.e
```
├── main.rs: `use thing::thang;`
└── thing.rs: `struct thang`
```
or
```
├── main.rs: `use thing::thang;`
└── thing
    └── mod.rs: `struct thang`
```
which currently is just
```rust
error[E0432]: unresolved import `yeah`
 --> src/main.rs:1:1
  |
1 | use thing::thang;
  |     ^^^^^ use of unresolved module or unlinked crate `thing`
  |
```
but now would have this nice help:
```text
= help: you may have forgotten to declare the module `thing`. use `mod thing` in this file to declare this module.
```
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/submodule/mod.rs1
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/submodule2.rs1
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/success.rs4
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/success/compiletest-ignore-dir0
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/success/submodule3/mod.rs1
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/success/submodule4.rs1
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/suggestion.rs7
-rw-r--r--tests/ui/modules/module_suggestion_when_module_not_found/suggestion.stderr49
-rw-r--r--tests/ui/modules_and_files_visibility/mod_file_disambig.stderr5
9 files changed, 68 insertions, 1 deletions
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/submodule/mod.rs b/tests/ui/modules/module_suggestion_when_module_not_found/submodule/mod.rs
new file mode 100644
index 00000000000..cb924172efe
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/submodule/mod.rs
@@ -0,0 +1 @@
+//@ ignore-auxiliary
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/submodule2.rs b/tests/ui/modules/module_suggestion_when_module_not_found/submodule2.rs
new file mode 100644
index 00000000000..cb924172efe
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/submodule2.rs
@@ -0,0 +1 @@
+//@ ignore-auxiliary
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/success.rs b/tests/ui/modules/module_suggestion_when_module_not_found/success.rs
new file mode 100644
index 00000000000..888e6ab3f19
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/success.rs
@@ -0,0 +1,4 @@
+//@ ignore-auxiliary
+
+use submodule3::ferris; // these modules are unresolved.
+use submodule4::error;
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/success/compiletest-ignore-dir b/tests/ui/modules/module_suggestion_when_module_not_found/success/compiletest-ignore-dir
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/success/compiletest-ignore-dir
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/success/submodule3/mod.rs b/tests/ui/modules/module_suggestion_when_module_not_found/success/submodule3/mod.rs
new file mode 100644
index 00000000000..8337712ea57
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/success/submodule3/mod.rs
@@ -0,0 +1 @@
+//
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/success/submodule4.rs b/tests/ui/modules/module_suggestion_when_module_not_found/success/submodule4.rs
new file mode 100644
index 00000000000..8337712ea57
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/success/submodule4.rs
@@ -0,0 +1 @@
+//
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/suggestion.rs b/tests/ui/modules/module_suggestion_when_module_not_found/suggestion.rs
new file mode 100644
index 00000000000..f4c24bff228
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/suggestion.rs
@@ -0,0 +1,7 @@
+//@ edition:2024
+use submodule::cat; //~ ERROR unresolved import `submodule`
+use submodule2::help; //~ ERROR unresolved import `submodule2`
+mod success;
+fn main() {}
+//~? ERROR unresolved import `submodule3`
+//~? ERROR unresolved import `submodule4`
diff --git a/tests/ui/modules/module_suggestion_when_module_not_found/suggestion.stderr b/tests/ui/modules/module_suggestion_when_module_not_found/suggestion.stderr
new file mode 100644
index 00000000000..6375d71c280
--- /dev/null
+++ b/tests/ui/modules/module_suggestion_when_module_not_found/suggestion.stderr
@@ -0,0 +1,49 @@
+error[E0432]: unresolved import `submodule`
+  --> $DIR/suggestion.rs:2:5
+   |
+LL | use submodule::cat;
+   |     ^^^^^^^^^ use of unresolved module or unlinked crate `submodule`
+   |
+help: to make use of source file $DIR/submodule/mod.rs, use `mod submodule` in this file to declare the module
+   |
+LL + mod submodule;
+   |
+
+error[E0432]: unresolved import `submodule2`
+  --> $DIR/suggestion.rs:3:5
+   |
+LL | use submodule2::help;
+   |     ^^^^^^^^^^ use of unresolved module or unlinked crate `submodule2`
+   |
+help: to make use of source file $DIR/submodule2.rs, use `mod submodule2` in this file to declare the module
+   |
+LL + mod submodule2;
+   |
+
+error[E0432]: unresolved import `submodule3`
+  --> $DIR/success.rs:3:5
+   |
+LL | use submodule3::ferris; // these modules are unresolved.
+   |     ^^^^^^^^^^ use of unresolved module or unlinked crate `submodule3`
+   |
+help: to make use of source file $DIR/success/submodule3/mod.rs, use `mod submodule3` in this file to declare the module
+  --> $DIR/suggestion.rs:2:1
+   |
+LL + mod submodule3;
+   |
+
+error[E0432]: unresolved import `submodule4`
+  --> $DIR/success.rs:4:5
+   |
+LL | use submodule4::error;
+   |     ^^^^^^^^^^ use of unresolved module or unlinked crate `submodule4`
+   |
+help: to make use of source file $DIR/success/submodule4.rs, use `mod submodule4` in this file to declare the module
+  --> $DIR/suggestion.rs:2:1
+   |
+LL + mod submodule4;
+   |
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0432`.
diff --git a/tests/ui/modules_and_files_visibility/mod_file_disambig.stderr b/tests/ui/modules_and_files_visibility/mod_file_disambig.stderr
index f82d613015f..e71a6de2fb9 100644
--- a/tests/ui/modules_and_files_visibility/mod_file_disambig.stderr
+++ b/tests/ui/modules_and_files_visibility/mod_file_disambig.stderr
@@ -12,7 +12,10 @@ error[E0433]: failed to resolve: use of unresolved module or unlinked crate `mod
 LL |     assert_eq!(mod_file_aux::bar(), 10);
    |                ^^^^^^^^^^^^ use of unresolved module or unlinked crate `mod_file_aux`
    |
-   = help: you might be missing a crate named `mod_file_aux`
+help: to make use of source file $DIR/mod_file_aux.rs, use `mod mod_file_aux` in this file to declare the module
+   |
+LL + mod mod_file_aux;
+   |
 
 error: aborting due to 2 previous errors