Skip to content

similar_names stop linting for 3-char names #15100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2025
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