Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCREAMING_SNAKE_CASE and UPPERCASE names don't get flagged by module_name_repetitions #13968

Open
mansf-osk opened this issue Jan 9, 2025 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@mansf-osk
Copy link

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.

pub fn to_camel_case(item_name: &str) -> String {
let mut s = String::new();
let mut up = true;
for c in item_name.chars() {
if c.is_uppercase() {
// we only turn snake case text into CamelCase
return item_name.to_string();
}

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.

let item_name = item.ident.name.as_str();
let item_camel = to_camel_case(item_name);

let matching = count_match_start(mod_camel, &item_camel);
let rmatching = count_match_end(mod_camel, &item_camel);

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
@mansf-osk mansf-osk added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

1 participant