Skip to content

Commit da4b212

Browse files
committed
Auto merge of #12859 - cookie-s:dedup-single-char-name-diag, r=Alexendoo
[`many_single_char_names`]: Deduplicate diagnostics Relates to #12379 Fix `many_single_char_names` lint so that it doesn't emit diagnostics when the current level of the scope doesn't contain any single character name. ```rust let (a, b, c, d): (i32, i32, i32, i32); match 1 { 1 => (), e => {}, } ``` produced the exact same MANY_SINGLE_CHAR_NAMES diagnostic at each of the Arm `e => {}` and the Block `{}`. --- changelog: [`many_single_char_names`]: Fix duplicate diagnostics
2 parents 76eee82 + 7110f47 commit da4b212

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

clippy_lints/src/non_expressive_names.rs

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ struct SimilarNamesLocalVisitor<'a, 'tcx> {
9898

9999
impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> {
100100
fn check_single_char_names(&self) {
101+
if self.single_char_names.last().map(Vec::len) == Some(0) {
102+
return;
103+
}
104+
101105
let num_single_char_names = self.single_char_names.iter().flatten().count();
102106
let threshold = self.lint.single_char_binding_names_threshold;
103107
if num_single_char_names as u64 > threshold {

tests/ui/many_single_char_names.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@compile-flags: -Zdeduplicate-diagnostics=yes
2-
31
#![allow(clippy::too_many_arguments, clippy::diverging_sub_expression)]
42
#![warn(clippy::many_single_char_names)]
53

tests/ui/many_single_char_names.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: 5 bindings with single-character names in scope
2-
--> tests/ui/many_single_char_names.rs:7:9
2+
--> tests/ui/many_single_char_names.rs:5:9
33
|
44
LL | let a: i32;
55
| ^
@@ -14,7 +14,7 @@ LL | let e: i32;
1414
= help: to override `-D warnings` add `#[allow(clippy::many_single_char_names)]`
1515

1616
error: 6 bindings with single-character names in scope
17-
--> tests/ui/many_single_char_names.rs:7:9
17+
--> tests/ui/many_single_char_names.rs:5:9
1818
|
1919
LL | let a: i32;
2020
| ^
@@ -28,7 +28,7 @@ LL | let f: i32;
2828
| ^
2929

3030
error: 5 bindings with single-character names in scope
31-
--> tests/ui/many_single_char_names.rs:7:9
31+
--> tests/ui/many_single_char_names.rs:5:9
3232
|
3333
LL | let a: i32;
3434
| ^
@@ -40,13 +40,13 @@ LL | e => panic!(),
4040
| ^
4141

4242
error: 8 bindings with single-character names in scope
43-
--> tests/ui/many_single_char_names.rs:36:13
43+
--> tests/ui/many_single_char_names.rs:34:13
4444
|
4545
LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {}
4646
| ^ ^ ^ ^ ^ ^ ^ ^
4747

4848
error: 8 bindings with single-character names in scope
49-
--> tests/ui/many_single_char_names.rs:40:10
49+
--> tests/ui/many_single_char_names.rs:38:10
5050
|
5151
LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!();
5252
| ^ ^ ^ ^ ^ ^ ^ ^

0 commit comments

Comments
 (0)