diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl index 6c7e68246ea5f..8b93829623dbf 100644 --- a/compiler/rustc_expand/messages.ftl +++ b/compiler/rustc_expand/messages.ftl @@ -86,6 +86,7 @@ expand_module_circular = expand_module_file_not_found = file not found for module `{$name}` .help = to create the module `{$name}`, create file "{$default_path}" or "{$secondary_path}" + .note = if there is a `mod {$name}` elsewhere in the crate already, import it with `use crate::...` instead expand_module_in_block = cannot declare a non-inline module inside a block unless it has a path attribute diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index e3a0ae3570eb0..d86632c47fc5d 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -350,6 +350,7 @@ pub(crate) struct ModuleInBlockName { #[derive(Diagnostic)] #[diag(expand_module_file_not_found, code = "E0583")] #[help] +#[note] pub(crate) struct ModuleFileNotFound { #[primary_span] pub span: Span, diff --git a/tests/ui/error-codes/E0583.stderr b/tests/ui/error-codes/E0583.stderr index c7bbbf114997d..6707f2864f23c 100644 --- a/tests/ui/error-codes/E0583.stderr +++ b/tests/ui/error-codes/E0583.stderr @@ -5,6 +5,7 @@ LL | mod module_that_doesnt_exist; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: to create the module `module_that_doesnt_exist`, create file "$DIR/module_that_doesnt_exist.rs" or "$DIR/module_that_doesnt_exist/mod.rs" + = note: if there is a `mod module_that_doesnt_exist` elsewhere in the crate already, import it with `use crate::...` instead error: aborting due to previous error diff --git a/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr b/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr index 7bc8efd7e4a97..08aec25928c0d 100644 --- a/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr +++ b/tests/ui/invalid-module-declaration/invalid-module-declaration.stderr @@ -5,6 +5,7 @@ LL | pub mod baz; | ^^^^^^^^^^^^ | = help: to create the module `baz`, create file "$DIR/auxiliary/foo/bar/baz.rs" or "$DIR/auxiliary/foo/bar/baz/mod.rs" + = note: if there is a `mod baz` elsewhere in the crate already, import it with `use crate::...` instead error: aborting due to previous error diff --git a/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod.stderr b/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod.stderr index 31e4206a5463a..5f4d19439accd 100644 --- a/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod.stderr +++ b/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod.stderr @@ -5,6 +5,7 @@ LL | mod missing; | ^^^^^^^^^^^^ | = help: to create the module `missing`, create file "$DIR/foo/missing.rs" or "$DIR/foo/missing/mod.rs" + = note: if there is a `mod missing` elsewhere in the crate already, import it with `use crate::...` instead error: aborting due to previous error diff --git a/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod_inline.stderr b/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod_inline.stderr index 9d252398b7a14..d5f5ea8705971 100644 --- a/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod_inline.stderr +++ b/tests/ui/missing_non_modrs_mod/missing_non_modrs_mod_inline.stderr @@ -5,6 +5,7 @@ LL | mod missing; | ^^^^^^^^^^^^ | = help: to create the module `missing`, create file "$DIR/foo_inline/inline/missing.rs" or "$DIR/foo_inline/inline/missing/mod.rs" + = note: if there is a `mod missing` elsewhere in the crate already, import it with `use crate::...` instead error: aborting due to previous error diff --git a/tests/ui/modules/special_module_name.stderr b/tests/ui/modules/special_module_name.stderr index bc4b4f1b3181c..84473bf8c0bc6 100644 --- a/tests/ui/modules/special_module_name.stderr +++ b/tests/ui/modules/special_module_name.stderr @@ -5,6 +5,7 @@ LL | mod lib; | ^^^^^^^^ | = help: to create the module `lib`, create file "$DIR/lib.rs" or "$DIR/lib/mod.rs" + = note: if there is a `mod lib` elsewhere in the crate already, import it with `use crate::...` instead error[E0583]: file not found for module `main` --> $DIR/special_module_name.rs:4:1 @@ -13,6 +14,7 @@ LL | mod main; | ^^^^^^^^^ | = help: to create the module `main`, create file "$DIR/main.rs" or "$DIR/main/mod.rs" + = note: if there is a `mod main` elsewhere in the crate already, import it with `use crate::...` instead warning: found module declaration for lib.rs --> $DIR/special_module_name.rs:1:1 diff --git a/tests/ui/parser/mod_file_not_exist.stderr b/tests/ui/parser/mod_file_not_exist.stderr index 62456d518804f..c2f9d30d9ec40 100644 --- a/tests/ui/parser/mod_file_not_exist.stderr +++ b/tests/ui/parser/mod_file_not_exist.stderr @@ -5,6 +5,7 @@ LL | mod not_a_real_file; | ^^^^^^^^^^^^^^^^^^^^ | = help: to create the module `not_a_real_file`, create file "$DIR/not_a_real_file.rs" or "$DIR/not_a_real_file/mod.rs" + = note: if there is a `mod not_a_real_file` elsewhere in the crate already, import it with `use crate::...` instead error[E0433]: failed to resolve: use of undeclared crate or module `mod_file_aux` --> $DIR/mod_file_not_exist.rs:7:16 diff --git a/tests/ui/parser/unsafe-mod.stderr b/tests/ui/parser/unsafe-mod.stderr index dac6e7a355056..fbe24aa10da42 100644 --- a/tests/ui/parser/unsafe-mod.stderr +++ b/tests/ui/parser/unsafe-mod.stderr @@ -5,6 +5,7 @@ LL | unsafe mod n; | ^^^^^^^^^^^^^ | = help: to create the module `n`, create file "$DIR/n.rs" or "$DIR/n/mod.rs" + = note: if there is a `mod n` elsewhere in the crate already, import it with `use crate::...` instead error: module cannot be declared unsafe --> $DIR/unsafe-mod.rs:1:1 diff --git a/tests/ui/rfcs/rfc-2457-non-ascii-idents/mod_file_nonascii_forbidden.stderr b/tests/ui/rfcs/rfc-2457-non-ascii-idents/mod_file_nonascii_forbidden.stderr index 7639ae9f6a4fd..8ca6a37c62518 100644 --- a/tests/ui/rfcs/rfc-2457-non-ascii-idents/mod_file_nonascii_forbidden.stderr +++ b/tests/ui/rfcs/rfc-2457-non-ascii-idents/mod_file_nonascii_forbidden.stderr @@ -5,6 +5,7 @@ LL | mod řųśť; | ^^^^^^^^^ | = help: to create the module `řųśť`, create file "$DIR/řųśť.rs" or "$DIR/řųśť/mod.rs" + = note: if there is a `mod řųśť` elsewhere in the crate already, import it with `use crate::...` instead error[E0754]: trying to load file for module `řųśť` with non-ascii identifier name --> $DIR/mod_file_nonascii_forbidden.rs:1:5