Skip to content

Commit e248813

Browse files
committed
Mention the syntax for use on mod foo; if foo doesn't exist
Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`. Fix #69492.
1 parent cc705b8 commit e248813

File tree

10 files changed

+11
-0
lines changed

10 files changed

+11
-0
lines changed

compiler/rustc_expand/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ expand_module_circular =
8686
expand_module_file_not_found =
8787
file not found for module `{$name}`
8888
.help = to create the module `{$name}`, create file "{$default_path}" or "{$secondary_path}"
89+
.note = if there is a `mod {$name} {"{"} ... {"}"}` elsewhere in the crate already, import it with `use crate::...` instead
8990
9091
expand_module_in_block =
9192
cannot declare a non-inline module inside a block unless it has a path attribute

compiler/rustc_expand/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ pub(crate) struct ModuleInBlockName {
350350
#[derive(Diagnostic)]
351351
#[diag(expand_module_file_not_found, code = "E0583")]
352352
#[help]
353+
#[note]
353354
pub(crate) struct ModuleFileNotFound {
354355
#[primary_span]
355356
pub span: Span,

tests/ui/error-codes/E0583.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | mod module_that_doesnt_exist;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= 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"
8+
= note: if there is a `mod module_that_doesnt_exist { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error: aborting due to previous error
1011

tests/ui/invalid-module-declaration/invalid-module-declaration.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | pub mod baz;
55
| ^^^^^^^^^^^^
66
|
77
= help: to create the module `baz`, create file "$DIR/auxiliary/foo/bar/baz.rs" or "$DIR/auxiliary/foo/bar/baz/mod.rs"
8+
= note: if there is a `mod baz { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error: aborting due to previous error
1011

tests/ui/missing_non_modrs_mod/missing_non_modrs_mod.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | mod missing;
55
| ^^^^^^^^^^^^
66
|
77
= help: to create the module `missing`, create file "$DIR/foo/missing.rs" or "$DIR/foo/missing/mod.rs"
8+
= note: if there is a `mod missing { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error: aborting due to previous error
1011

tests/ui/missing_non_modrs_mod/missing_non_modrs_mod_inline.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | mod missing;
55
| ^^^^^^^^^^^^
66
|
77
= help: to create the module `missing`, create file "$DIR/foo_inline/inline/missing.rs" or "$DIR/foo_inline/inline/missing/mod.rs"
8+
= note: if there is a `mod missing { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error: aborting due to previous error
1011

tests/ui/modules/special_module_name.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | mod lib;
55
| ^^^^^^^^
66
|
77
= help: to create the module `lib`, create file "$DIR/lib.rs" or "$DIR/lib/mod.rs"
8+
= note: if there is a `mod lib { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error[E0583]: file not found for module `main`
1011
--> $DIR/special_module_name.rs:4:1
@@ -13,6 +14,7 @@ LL | mod main;
1314
| ^^^^^^^^^
1415
|
1516
= help: to create the module `main`, create file "$DIR/main.rs" or "$DIR/main/mod.rs"
17+
= note: if there is a `mod main { ... }` elsewhere in the crate already, import it with `use crate::...` instead
1618

1719
warning: found module declaration for lib.rs
1820
--> $DIR/special_module_name.rs:1:1

tests/ui/parser/mod_file_not_exist.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | mod not_a_real_file;
55
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
= 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"
8+
= note: if there is a `mod not_a_real_file { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error[E0433]: failed to resolve: use of undeclared crate or module `mod_file_aux`
1011
--> $DIR/mod_file_not_exist.rs:7:16

tests/ui/parser/unsafe-mod.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | unsafe mod n;
55
| ^^^^^^^^^^^^^
66
|
77
= help: to create the module `n`, create file "$DIR/n.rs" or "$DIR/n/mod.rs"
8+
= note: if there is a `mod n { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error: module cannot be declared unsafe
1011
--> $DIR/unsafe-mod.rs:1:1

tests/ui/rfcs/rfc-2457-non-ascii-idents/mod_file_nonascii_forbidden.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | mod řųśť;
55
| ^^^^^^^^^
66
|
77
= help: to create the module `řųśť`, create file "$DIR/řųśť.rs" or "$DIR/řųśť/mod.rs"
8+
= note: if there is a `mod řųśť { ... }` elsewhere in the crate already, import it with `use crate::...` instead
89

910
error[E0754]: trying to load file for module `řųśť` with non-ascii identifier name
1011
--> $DIR/mod_file_nonascii_forbidden.rs:1:5

0 commit comments

Comments
 (0)