@@ -162,6 +162,7 @@ pub struct ItemNameRepetitions {
162162 enum_threshold : u64 ,
163163 struct_threshold : u64 ,
164164 avoid_breaking_exported_api : bool ,
165+ allow_exact_repetitions : bool ,
165166 allow_private_module_inception : bool ,
166167 allowed_prefixes : FxHashSet < String > ,
167168}
@@ -173,6 +174,7 @@ impl ItemNameRepetitions {
173174 enum_threshold : conf. enum_variant_name_threshold ,
174175 struct_threshold : conf. struct_field_name_threshold ,
175176 avoid_breaking_exported_api : conf. avoid_breaking_exported_api ,
177+ allow_exact_repetitions : conf. allow_exact_repetitions ,
176178 allow_private_module_inception : conf. allow_private_module_inception ,
177179 allowed_prefixes : conf. allowed_prefixes . iter ( ) . map ( |s| to_camel_case ( s) ) . collect ( ) ,
178180 }
@@ -486,11 +488,21 @@ impl LateLintPass<'_> for ItemNameRepetitions {
486488 }
487489
488490 // The `module_name_repetitions` lint should only trigger if the item has the module in its
489- // name. Having the same name is accepted.
490- if cx. tcx . visibility ( item. owner_id ) . is_public ( )
491- && cx. tcx . visibility ( mod_owner_id. def_id ) . is_public ( )
492- && item_camel. len ( ) > mod_camel. len ( )
493- {
491+ // name. Having the same name is only accepted if `allow_exact_repetition` is set to `true`.
492+
493+ let both_are_public =
494+ cx. tcx . visibility ( item. owner_id ) . is_public ( ) && cx. tcx . visibility ( mod_owner_id. def_id ) . is_public ( ) ;
495+
496+ if both_are_public && !self . allow_exact_repetitions && item_camel == * mod_camel {
497+ span_lint (
498+ cx,
499+ MODULE_NAME_REPETITIONS ,
500+ ident. span ,
501+ "item name is the same as its containing module's name" ,
502+ ) ;
503+ }
504+
505+ if both_are_public && item_camel. len ( ) > mod_camel. len ( ) {
494506 let matching = count_match_start ( mod_camel, & item_camel) ;
495507 let rmatching = count_match_end ( mod_camel, & item_camel) ;
496508 let nchars = mod_camel. chars ( ) . count ( ) ;
0 commit comments