diff options
| author | yanglsh <yanglsh@shanghaitech.edu.cn> | 2025-07-21 21:49:41 +0800 |
|---|---|---|
| committer | yanglsh <yanglsh@shanghaitech.edu.cn> | 2025-07-21 21:49:41 +0800 |
| commit | bebae76f2396a61499e6e01dcf8f0b510f9fd856 (patch) | |
| tree | 7d3d2924554b5b4e1dda960f67b8c061fc20fcb7 | |
| parent | ae8ff77d00f04cee9512c5b7d0bce7d61976bfaa (diff) | |
| download | rust-bebae76f2396a61499e6e01dcf8f0b510f9fd856.tar.gz rust-bebae76f2396a61499e6e01dcf8f0b510f9fd856.zip | |
fix: `module_name_repetitions` 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) => { + /* ... */ + }; + } + } +} |
