rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
10.89k stars 1.46k forks source link

Allow numbers in module_name_repetitions #12714

Open TomFryersMidsummer opened 2 weeks ago

TomFryersMidsummer commented 2 weeks ago

Summary

Suppose I have a module vector, containing a Vector2 type. This seems fine to me – I can't name the type 2, after all. However module_name_repetitions disagrees.

Maybe this should apply to all short affixes more generally (one or perhaps two letters). I'm not sure.

Lint Name

module_name_repetitions

Reproducer

I tried this code:

pub mod vector {
    pub struct Vector2(pub f64, pub f64);
}

I saw this happen:

$ clippy-driver --crate-type lib -Wclippy::pedantic test.rs 
warning: item name starts with its containing module's name
 --> test.rs:2:16
  |
2 |     pub struct Vector2(pub f64, pub f64);
  |                ^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions
  = note: `-W clippy::module-name-repetitions` implied by `-W clippy::pedantic`
  = help: to override `-W clippy::pedantic` add `#[allow(clippy::module_name_repetitions)]`

warning: 1 warning emitted

I expected to see this happen: [no error]

Version

rustc 1.79.0-nightly (ef8b9dcf2 2024-04-24)
binary: rustc
commit-hash: ef8b9dcf23700f2e2265317611460d3a65c19eff
commit-date: 2024-04-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Additional Labels

No response