Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ expand_module_file_not_found =
.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
.note = maybe `use` the module `{$name}` instead of redeclaring it
cannot declare an external module inside a block unless it has a path attribute
.help = maybe `use` the module `{$name}` instead of redeclaring it
.note = external modules are usually placed outside of blocks, at the top level of the file
expand_module_multiple_candidates =
file for module `{$name}` found at both "{$default_path}" and "{$secondary_path}"
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ pub(crate) struct ModuleCircular {

#[derive(Diagnostic)]
#[diag(expand_module_in_block)]
#[note]
pub(crate) struct ModuleInBlock {
#[primary_span]
pub span: Span,
Expand All @@ -273,7 +274,7 @@ pub(crate) struct ModuleInBlock {
}

#[derive(Subdiagnostic)]
#[note(expand_note)]
#[help(expand_help)]
pub(crate) struct ModuleInBlockName {
#[primary_span]
pub span: Span,
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/directory_ownership/external-mod-restriction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test that external modules are not allowed inside blocks.

fn main() {
mod foo; //~ ERROR cannot declare an external module inside a block unless it has a path attribute
}
10 changes: 10 additions & 0 deletions tests/ui/directory_ownership/external-mod-restriction.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: cannot declare an external module inside a block unless it has a path attribute
--> $DIR/external-mod-restriction.rs:4:5
|
LL | mod foo;
| ^^^^^^^^
|
= note: external modules are usually placed outside of blocks, at the top level of the file

error: aborting due to 1 previous error

2 changes: 1 addition & 1 deletion tests/ui/directory_ownership/macro-expanded-mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

macro_rules! mod_decl {
($i:ident) => {
mod $i; //~ ERROR cannot declare a non-inline module inside a block
mod $i; //~ ERROR cannot declare an external module inside a block unless it has a path attribute
};
}

Expand Down
3 changes: 2 additions & 1 deletion tests/ui/directory_ownership/macro-expanded-mod.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: cannot declare a non-inline module inside a block unless it has a path attribute
error: cannot declare an external module inside a block unless it has a path attribute
--> $DIR/macro-expanded-mod.rs:5:9
|
LL | mod $i;
Expand All @@ -7,6 +7,7 @@ LL | mod $i;
LL | mod_decl!(foo);
| -------------- in this macro invocation
|
= note: external modules are usually placed outside of blocks, at the top level of the file
= note: this error originates in the macro `mod_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error
Expand Down
5 changes: 0 additions & 5 deletions tests/ui/directory_ownership/non-inline-mod-restriction.rs

This file was deleted.

This file was deleted.

Loading