Description
Summary
While refactoring code to adhere to module_name_repetitions
we noticed that our constants wouldn't get flagged.
Example
mod foo {
#![warn(clippy::module_name_repetitions)]
pub const FOO_CONSTANT: usize = 0; // lint does not work
pub fn foo_function() {} // lint gives warning
pub struct FooStruct; // lint gives warning
}
This seems like it might be a bug, as I think the reasoning given in the lint description as well as the arguments given in the discussion around RFC #356 also apply to constants.
Cause
After doing some investigation this appears to be happening due to how to_camel_case()
in clippy_utils::str_utils
handles uppercase input.
rust-clippy/clippy_utils/src/str_utils.rs
Lines 270 to 277 in 894e87c
Because of the early return here the comparison between item_camel
and mod_camel
in item_name_repetitions.rs
returns false and the SCREAMING_SNAKE_CASE
name doesn't get flagged by the lint.
rust-clippy/clippy_lints/src/item_name_repetitions.rs
Lines 406 to 407 in 894e87c
rust-clippy/clippy_lints/src/item_name_repetitions.rs
Lines 430 to 431 in 894e87c
If this is a bug indeed and the behavior is not intentional I'd be happy to work on a fix and put in a pull-request!
Lint Name
module_name_repetitions
Reproducer
No response
Version
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1