@@ -162,6 +162,7 @@ pub struct ItemNameRepetitions {
162
162
enum_threshold : u64 ,
163
163
struct_threshold : u64 ,
164
164
avoid_breaking_exported_api : bool ,
165
+ allow_exact_repetitions : bool ,
165
166
allow_private_module_inception : bool ,
166
167
allowed_prefixes : FxHashSet < String > ,
167
168
}
@@ -173,6 +174,7 @@ impl ItemNameRepetitions {
173
174
enum_threshold : conf. enum_variant_name_threshold ,
174
175
struct_threshold : conf. struct_field_name_threshold ,
175
176
avoid_breaking_exported_api : conf. avoid_breaking_exported_api ,
177
+ allow_exact_repetitions : conf. allow_exact_repetitions ,
176
178
allow_private_module_inception : conf. allow_private_module_inception ,
177
179
allowed_prefixes : conf. allowed_prefixes . iter ( ) . map ( |s| to_camel_case ( s) ) . collect ( ) ,
178
180
}
@@ -486,11 +488,21 @@ impl LateLintPass<'_> for ItemNameRepetitions {
486
488
}
487
489
488
490
// 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 ( ) {
494
506
let matching = count_match_start ( mod_camel, & item_camel) ;
495
507
let rmatching = count_match_end ( mod_camel, & item_camel) ;
496
508
let nchars = mod_camel. chars ( ) . count ( ) ;
0 commit comments