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
This commit is contained in:
bors 2024-05-28 12:41:14 +00:00
commit da4b2127c0
3 changed files with 9 additions and 7 deletions

View File

@ -98,6 +98,10 @@ struct SimilarNamesLocalVisitor<'a, 'tcx> {
impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> {
fn check_single_char_names(&self) {
if self.single_char_names.last().map(Vec::len) == Some(0) {
return;
}
let num_single_char_names = self.single_char_names.iter().flatten().count();
let threshold = self.lint.single_char_binding_names_threshold;
if num_single_char_names as u64 > threshold {

View File

@ -1,5 +1,3 @@
//@compile-flags: -Zdeduplicate-diagnostics=yes
#![allow(clippy::too_many_arguments, clippy::diverging_sub_expression)]
#![warn(clippy::many_single_char_names)]

View File

@ -1,5 +1,5 @@
error: 5 bindings with single-character names in scope
--> tests/ui/many_single_char_names.rs:7:9
--> tests/ui/many_single_char_names.rs:5:9
|
LL | let a: i32;
| ^
@ -14,7 +14,7 @@ LL | let e: i32;
= help: to override `-D warnings` add `#[allow(clippy::many_single_char_names)]`
error: 6 bindings with single-character names in scope
--> tests/ui/many_single_char_names.rs:7:9
--> tests/ui/many_single_char_names.rs:5:9
|
LL | let a: i32;
| ^
@ -28,7 +28,7 @@ LL | let f: i32;
| ^
error: 5 bindings with single-character names in scope
--> tests/ui/many_single_char_names.rs:7:9
--> tests/ui/many_single_char_names.rs:5:9
|
LL | let a: i32;
| ^
@ -40,13 +40,13 @@ LL | e => panic!(),
| ^
error: 8 bindings with single-character names in scope
--> tests/ui/many_single_char_names.rs:36:13
--> tests/ui/many_single_char_names.rs:34:13
|
LL | fn bindings(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32, h: i32) {}
| ^ ^ ^ ^ ^ ^ ^ ^
error: 8 bindings with single-character names in scope
--> tests/ui/many_single_char_names.rs:40:10
--> tests/ui/many_single_char_names.rs:38:10
|
LL | let (a, b, c, d, e, f, g, h): (bool, bool, bool, bool, bool, bool, bool, bool) = unimplemented!();
| ^ ^ ^ ^ ^ ^ ^ ^