Skip to content

Commit 8ad5c67

Browse files
authored
Fix module_name_repetitions FP on exported macros (#15319)
Closes #14095 changelog: [`module_name_repetitions`] fix FP on exported macros
2 parents b2c8c02 + bebae76 commit 8ad5c67

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clippy_lints/src/item_name_repetitions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet;
88
use rustc_hir::{EnumDef, FieldDef, Item, ItemKind, OwnerId, QPath, TyKind, Variant, VariantData};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_session::impl_lint_pass;
11+
use rustc_span::MacroKind;
1112
use rustc_span::symbol::Symbol;
1213

1314
declare_clippy_lint! {
@@ -502,7 +503,8 @@ impl LateLintPass<'_> for ItemNameRepetitions {
502503
);
503504
}
504505

505-
if both_are_public && item_camel.len() > mod_camel.len() {
506+
let is_macro_rule = matches!(item.kind, ItemKind::Macro(_, _, MacroKind::Bang));
507+
if both_are_public && item_camel.len() > mod_camel.len() && !is_macro_rule {
506508
let matching = count_match_start(mod_camel, &item_camel);
507509
let rmatching = count_match_end(mod_camel, &item_camel);
508510
let nchars = mod_camel.chars().count();

tests/ui/module_name_repetitions.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,21 @@ pub mod foo {
5555
}
5656

5757
fn main() {}
58+
59+
pub mod issue14095 {
60+
pub mod widget {
61+
#[macro_export]
62+
macro_rules! define_widget {
63+
($id:ident) => {
64+
/* ... */
65+
};
66+
}
67+
68+
#[macro_export]
69+
macro_rules! widget_impl {
70+
($id:ident) => {
71+
/* ... */
72+
};
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)