diff options
| author | Alejandra González <blyxyas@gmail.com> | 2025-07-23 23:11:01 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-23 23:11:01 +0000 |
| commit | 8ad5c67ff9c39e2dc87c366a33169f197f14ae5c (patch) | |
| tree | fb238c1c075412a984b4bda8a0e19fde7b179ea3 | |
| parent | b2c8c02a02e7bccd7e44f6396844723eb384cd37 (diff) | |
| parent | bebae76f2396a61499e6e01dcf8f0b510f9fd856 (diff) | |
| download | rust-8ad5c67ff9c39e2dc87c366a33169f197f14ae5c.tar.gz rust-8ad5c67ff9c39e2dc87c366a33169f197f14ae5c.zip | |
Fix `module_name_repetitions` FP on exported macros (#15319)
Closes rust-lang/rust-clippy#14095 changelog: [`module_name_repetitions`] fix FP on exported macros
| -rw-r--r-- | clippy_lints/src/item_name_repetitions.rs | 4 | ||||
| -rw-r--r-- | tests/ui/module_name_repetitions.rs | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/clippy_lints/src/item_name_repetitions.rs b/clippy_lints/src/item_name_repetitions.rs index 9c91cf68085..95e16aae40f 100644 --- a/clippy_lints/src/item_name_repetitions.rs +++ b/clippy_lints/src/item_name_repetitions.rs @@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir::{EnumDef, FieldDef, Item, ItemKind, OwnerId, QPath, TyKind, Variant, VariantData}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; +use rustc_span::MacroKind; use rustc_span::symbol::Symbol; declare_clippy_lint! { @@ -502,7 +503,8 @@ impl LateLintPass<'_> for ItemNameRepetitions { ); } - if both_are_public && item_camel.len() > mod_camel.len() { + let is_macro_rule = matches!(item.kind, ItemKind::Macro(_, _, MacroKind::Bang)); + if both_are_public && item_camel.len() > mod_camel.len() && !is_macro_rule { let matching = count_match_start(mod_camel, &item_camel); let rmatching = count_match_end(mod_camel, &item_camel); let nchars = mod_camel.chars().count(); diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index 2fde98d7927..5d16858bf85 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -55,3 +55,21 @@ pub mod foo { } fn main() {} + +pub mod issue14095 { + pub mod widget { + #[macro_export] + macro_rules! define_widget { + ($id:ident) => { + /* ... */ + }; + } + + #[macro_export] + macro_rules! widget_impl { + ($id:ident) => { + /* ... */ + }; + } + } +} |
