Skip to content

module_name_repetitions false positive when in private module

Open

Description

Summary

When organizing large modules, I sometimes want to split a module into multiple files, but re-export all of the contents as if the module were one single module. The public interface to the module doesn't have any module name repetitions in my example below, yet the warning is still emitted because the containing module's scope isn't considered.

I believe this lint should be tightened to only emit if the module name that is being repeated is pub (and maybe pub(crate) but I trust others to make that judgement call).

This affects me often enough that I regularly disable this lint in my projects. This morning, I came up with the idea that maybe the lint could be tightened up in this particular situation.

Lint Name

module_name_repetitions

Reproducer

I tried this code:

#![warn(clippy::module_name_repetitions)]

mod error {
    pub enum Error {}
    pub enum OtherError {}
}

pub use error::{Error, OtherError};

I saw this happen:

warning: item name ends with its containing module's name
 --> src/main.rs:5:5
  |
5 |     pub enum OtherError {}
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::module_name_repetitions)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions

I expected no warnings to be emitted.

Version

rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0

Additional Labels

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions