Skip to content

Commit c917e02

Browse files
authored
Rollup merge of rust-lang#147395 - reddevilmidzy:refact-error-msg, r=Kivooeo,jackh726
Improve diagnostics: update note and add help message I moved the content from the note to a help message, as it seemed more appropriate there, and then added new information to the note(`Modules are usually placed outside of blocks, at the top level of the file`)! resolve: rust-lang#147314
2 parents 294c358 + 02126ad commit c917e02

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ expand_module_file_not_found =
118118
.note = if there is a `mod {$name}` elsewhere in the crate already, import it with `use crate::...` instead
119119
120120
expand_module_in_block =
121-
cannot declare a non-inline module inside a block unless it has a path attribute
122-
.note = maybe `use` the module `{$name}` instead of redeclaring it
121+
cannot declare a file module inside a block unless it has a path attribute
122+
.help = maybe `use` the module `{$name}` instead of redeclaring it
123+
.note = file modules are usually placed outside of blocks, at the top level of the file
123124
124125
expand_module_multiple_candidates =
125126
file for module `{$name}` found at both "{$default_path}" and "{$secondary_path}"

compiler/rustc_expand/src/errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ pub(crate) struct ModuleCircular {
265265

266266
#[derive(Diagnostic)]
267267
#[diag(expand_module_in_block)]
268+
#[note]
268269
pub(crate) struct ModuleInBlock {
269270
#[primary_span]
270271
pub span: Span,
@@ -273,7 +274,7 @@ pub(crate) struct ModuleInBlock {
273274
}
274275

275276
#[derive(Subdiagnostic)]
276-
#[note(expand_note)]
277+
#[help(expand_help)]
277278
pub(crate) struct ModuleInBlockName {
278279
#[primary_span]
279280
pub span: Span,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Test that file modules are not allowed inside blocks.
2+
3+
fn main() {
4+
mod foo; //~ ERROR cannot declare a file module inside a block unless it has a path attribute
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: cannot declare a file module inside a block unless it has a path attribute
2+
--> $DIR/file-mod-restriction.rs:4:5
3+
|
4+
LL | mod foo;
5+
| ^^^^^^^^
6+
|
7+
= note: file modules are usually placed outside of blocks, at the top level of the file
8+
9+
error: aborting due to 1 previous error
10+

tests/ui/directory_ownership/macro-expanded-mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Test that macro-expanded non-inline modules behave correctly
1+
// Test that macro-expanded file modules behave correctly
22

33
macro_rules! mod_decl {
44
($i:ident) => {
5-
mod $i; //~ ERROR cannot declare a non-inline module inside a block
5+
mod $i; //~ ERROR cannot declare a file module inside a block unless it has a path attribute
66
};
77
}
88

tests/ui/directory_ownership/macro-expanded-mod.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot declare a non-inline module inside a block unless it has a path attribute
1+
error: cannot declare a file module inside a block unless it has a path attribute
22
--> $DIR/macro-expanded-mod.rs:5:9
33
|
44
LL | mod $i;
@@ -7,6 +7,7 @@ LL | mod $i;
77
LL | mod_decl!(foo);
88
| -------------- in this macro invocation
99
|
10+
= note: file modules are usually placed outside of blocks, at the top level of the file
1011
= note: this error originates in the macro `mod_decl` (in Nightly builds, run with -Z macro-backtrace for more info)
1112

1213
error: aborting due to 1 previous error

tests/ui/directory_ownership/non-inline-mod-restriction.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/ui/directory_ownership/non-inline-mod-restriction.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)