Skip to content

Commit 3b35f51

Browse files
committed
Improve diagnostics: update note and add help message
1 parent 99ca0ae commit 3b35f51

File tree

6 files changed

+9
-4
lines changed

6 files changed

+9
-4
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ expand_module_file_not_found =
119119
120120
expand_module_in_block =
121121
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
122+
.help = maybe `use` the module `{$name}` instead of redeclaring it
123+
.note = 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,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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 non-inline module inside a block unless it has a path attribute
66
};
77
}
88

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | mod $i;
77
LL | mod_decl!(foo);
88
| -------------- in this macro invocation
99
|
10+
= note: 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
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Test that non-inline modules are not allowed inside blocks.
22

33
fn main() {
4-
mod foo; //~ ERROR cannot declare a non-inline module inside a block
4+
mod foo; //~ ERROR cannot declare a non-inline module inside a block unless it has a path attribute
55
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: cannot declare a non-inline module inside a block unless it has a path at
33
|
44
LL | mod foo;
55
| ^^^^^^^^
6+
|
7+
= note: modules are usually placed outside of blocks, at the top level of the file
68

79
error: aborting due to 1 previous error
810

0 commit comments

Comments
 (0)