Skip to content

module_name_repetitions on exported macros should use crate name, not module name #14095

@bonzini

Description

@bonzini

Summary

Exported macros end up as symbols on the crate, leading to an almost-certain module_name_repetitions false positive.

Lint Name

module_name_repetitions

Reproducer

I tried this code:

pub mod widget {
    #[macro_export]
    macro_rules! define_widget {
        ($id:ident) => { /* ... */ }
    }
}

with this invocation of clippy-driver:

$ clippy-driver foo.rs -D clippy::module_name_repetitions --crate-type lib

I saw this happen:

error: item name ends with its containing module's name
 --> f.rs:3:18
  |
3 |     macro_rules! define_widget {
  |                  ^^^^^^^^^^^^^
  |

I expected to see this happen:

No warning. The macro is imported with use foo::define_widget rather than use foo::widget::define_widget, thus there's no repetition.

Version

rustc 1.84.0-nightly (bc5cf994d 2024-11-05)
binary: rustc
commit-hash: bc5cf994db9fb46712cefd89f78ad7fc51f184a2
commit-date: 2024-11-05
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: 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