Skip to content

new module style lint: inline_module#16732

Open
zihan0822 wants to merge 1 commit intorust-lang:masterfrom
zihan0822:no-inline-module
Open

new module style lint: inline_module#16732
zihan0822 wants to merge 1 commit intorust-lang:masterfrom
zihan0822:no-inline-module

Conversation

@zihan0822
Copy link
Copy Markdown
Contributor

@zihan0822 zihan0822 commented Mar 19, 2026

fixes: #15966

add new module style restriction lint that checks for use of inline module, with an exception for test module.

changelog: new lint: [inline_module]

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 19, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 19, 2026

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 19, 2026

Lintcheck changes for f10dc9d

Lint Added Removed Changed
clippy::inline_module 431 0 0

This comment will be updated if you push new changes

module

changelog: new lint: [`inline_module`]

Signed-off-by: Zihan <zihanli0822@gmail.com>
@dswij
Copy link
Copy Markdown
Member

dswij commented Mar 25, 2026

r? clippy

@rustbot rustbot assigned ada4a and unassigned dswij Mar 25, 2026
Copy link
Copy Markdown
Contributor

@ada4a ada4a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some things to start, I think it will be easier to continue the review once they are addressed

View changes since this review

1 | mod foo {}
| ^^^^^^^
|
= help: move to `src/stuff/foo/mod.rs` or `src/stuff/foo.rs`
Copy link
Copy Markdown
Contributor

@ada4a ada4a Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't think this will even work, and there are not one but two interesting reasons!

First of all, it looks like you can't really "outline" inline modules called the same as their parent if the parent module is defined using #[path]. For example, in this code:

// `src/lib.rs`
#[path = "foo.rs"]
mod stuff;

// `src/foo.rs`
mod foo {
    // contents
}

you can't move the inline mod foo into a separate file, because wherever you move it, you'll need to leave mod foo; in its place, and that causes an error:

error: circular modules: src/foo.rs -> src/foo.rs
 --> src/foo.rs:1:1
  |
1 | mod foo;
  | ^^^^^^^^

error: could not compile `test` (bin "test") due to 1 previous error

Secondly and relatedly, even if you rename the child module to something different:

// `src/lib.rs`
#[path = "foo.rs"]
mod stuff;

// `src/foo.rs`
mod bar {
    /* contents of `bar` */
}

, the currently suggested path would be src/stuff/bar.rs, but it looks like what the compiler actually wants is just src/bar.rs?.. Honestly I would've expected src/foo/bar.rs.

As you can see, very weird things are happening here. So imo it would be the easiest to just not deal with any modules whose parent (I think grandparents should be fine, but please check that) has the #[path] attribute

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restriction lint for inline modules, or nested inline modules

4 participants