rust-lang / rust-lang/rust-clippy

`module_inception` false positive for private sub-module

Open
#13,259 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

When splitting a public module up into sub-modules for code-organization purposes, you can commonly have a sub-module with the same name as the public module. This is fine for a private module since the repetition isn't exposed to the outside world.

Lint Name

module_inception

Reproducer

I tried this code:

pub mod foo {
    mod foo {
        pub struct Foo;
    }

    // other private modules
    
    pub use self::foo::Foo;
    // other re-exports
}

I saw this happen:

warning: module has the same name as its containing module
 --> src/lib.rs:2:5
  |
2 | /     mod foo {
3 | |         pub struct Foo;
4 | |     }
  | |_____^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception
  = note: `#[warn(clippy::module_inception)]` on by default

I expected to see this happen: no warning

Version

No response

Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the module_inception lint implementation and reproduce the report's example in src/lib.rs. Check the lint's handling of a private sub-module with the same name as its public containing module; done means the example emits no warning while other module_inception cases remain covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.