Skip to content

Non-inline module is allowed inside other items #29765

@huonw

Description

@huonw

These are all legal, and somewhat strange, since they're not really following the file-system analogy that modules are typically explained with. I expect this behaviour is just whatever happens to fall out of the current implementation strategy, so let's make a more explicit decision one way or another.

static X: u8 = { mod foo; 0 };
fn foo() {
    mod foo;
}
fn main() {
    mod foo;
}

As one might expect, each of these is a distinct instance of foo (which can be verified by placing log_syntax(hello) in foo.rs: the compiler will greet you 3 times).

Noticed in https://users.rust-lang.org/t/are-module-declarations-allowed-inside-functions/3583 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTP-mediumMedium priorityT-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions