Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ impl SimilarNamesNameVisitor<'_, '_, '_> {
continue;
}

// Skip similarity check if both names are exactly 3 characters
if count == 3 && existing_name.len == 3 {
continue;
}

let dissimilar = match existing_name.len.cmp(&count) {
Ordering::Greater => existing_name.len - count != 1 || levenstein_not_1(interned_name, existing_str),
Ordering::Less => count - existing_name.len != 1 || levenstein_not_1(existing_str, interned_name),
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/ast_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> b
over(&l.attrs, &r.attrs, eq_attr) && eq_vis(&l.vis, &r.vis) && eq_kind(&l.kind, &r.kind)
}

#[expect(clippy::similar_names, clippy::too_many_lines)] // Just a big match statement
#[expect(clippy::too_many_lines)] // Just a big match statement
pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
use ItemKind::*;
match (l, r) {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/similar_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ fn main() {

let iter: i32;
let item: i32;

// 3 letter names are allowed to be similar
let kta: i32;
let ktv: i32;
}

fn foo() {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/similar_names.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ LL | let parser: i32;
| ^^^^^^

error: binding's name is too similar to existing binding
--> tests/ui/similar_names.rs:98:16
--> tests/ui/similar_names.rs:102:16
|
LL | bpple: sprang,
| ^^^^^^
|
note: existing binding defined here
--> tests/ui/similar_names.rs:97:16
--> tests/ui/similar_names.rs:101:16
|
LL | apple: spring,
| ^^^^^^
Expand Down