Skip to content

Commit

Permalink
Auto merge of rust-lang#12859 - cookie-s:dedup-single-char-name-diag,…
Browse files Browse the repository at this point in the history
… r=Alexendoo

[`many_single_char_names`]: Deduplicate diagnostics

Relates to rust-lang#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
  • Loading branch information
bors committed May 28, 2024
2 parents 76eee82 + 7110f47 commit da4b212
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/many_single_char_names.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@compile-flags: -Zdeduplicate-diagnostics=yes

#![allow(clippy::too_many_arguments, clippy::diverging_sub_expression)]
#![warn(clippy::many_single_char_names)]

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/many_single_char_names.stderr
Original file line number Diff line number Diff line change
@@ -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;
| ^
Expand All @@ -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;
| ^
Expand All @@ -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;
| ^
Expand All @@ -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!();
| ^ ^ ^ ^ ^ ^ ^ ^
Expand Down

0 comments on commit da4b212

Please sign in to comment.