Skip to content

Commit 1fd9504

Browse files
authored
similar_names stop linting for 3-char names (#15100)
fixes #14869 Added a simple check if both chars are of length 3 If they are, we skip the check for that pair. This won't handle the 4 v 3 case. Not sure if this was the intent of the issue. Also saw we have some hardcoded exemptions for `set, get` and `lhs, rhs` Tried removing them thinking they would be handled by the new condition. But we have to keep because they allow for `bla_lhs` v `bla_rhs` to be skipped changelog:[`similar_names`]: Stop triggering for 3-character names
2 parents aa8b09d + e41fb7c commit 1fd9504

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

clippy_lints/src/non_expressive_names.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ impl SimilarNamesNameVisitor<'_, '_, '_> {
248248
continue;
249249
}
250250

251+
// Skip similarity check if both names are exactly 3 characters
252+
if count == 3 && existing_name.len == 3 {
253+
continue;
254+
}
255+
251256
let dissimilar = match existing_name.len.cmp(&count) {
252257
Ordering::Greater => existing_name.len - count != 1 || levenstein_not_1(interned_name, existing_str),
253258
Ordering::Less => count - existing_name.len != 1 || levenstein_not_1(existing_str, interned_name),

clippy_utils/src/ast_utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pub fn eq_item<K>(l: &Item<K>, r: &Item<K>, mut eq_kind: impl FnMut(&K, &K) -> b
325325
over(&l.attrs, &r.attrs, eq_attr) && eq_vis(&l.vis, &r.vis) && eq_kind(&l.kind, &r.kind)
326326
}
327327

328-
#[expect(clippy::similar_names, clippy::too_many_lines)] // Just a big match statement
328+
#[expect(clippy::too_many_lines)] // Just a big match statement
329329
pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
330330
use ItemKind::*;
331331
match (l, r) {

tests/ui/similar_names.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ fn main() {
8989

9090
let iter: i32;
9191
let item: i32;
92+
93+
// 3 letter names are allowed to be similar
94+
let kta: i32;
95+
let ktv: i32;
9296
}
9397

9498
fn foo() {

tests/ui/similar_names.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ LL | let parser: i32;
4949
| ^^^^^^
5050

5151
error: binding's name is too similar to existing binding
52-
--> tests/ui/similar_names.rs:98:16
52+
--> tests/ui/similar_names.rs:102:16
5353
|
5454
LL | bpple: sprang,
5555
| ^^^^^^
5656
|
5757
note: existing binding defined here
58-
--> tests/ui/similar_names.rs:97:16
58+
--> tests/ui/similar_names.rs:101:16
5959
|
6060
LL | apple: spring,
6161
| ^^^^^^

0 commit comments

Comments
 (0)