From f2d493504cb863a30f45e8a0d5717285823f931e Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 28 Nov 2020 16:56:59 -0600 Subject: [PATCH] Similar names ignore underscore prefixed names --- clippy_lints/src/non_expressive_names.rs | 4 ++++ tests/ui/similar_names.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 446426b3e..855529378 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -199,6 +199,10 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> { ); return; } + if interned_name.starts_with('_') { + // these bindings are typically unused or represent an ignored portion of a destructuring pattern + return; + } let count = interned_name.chars().count(); if count < 3 { if count == 1 { diff --git a/tests/ui/similar_names.rs b/tests/ui/similar_names.rs index 6796b1528..598198098 100644 --- a/tests/ui/similar_names.rs +++ b/tests/ui/similar_names.rs @@ -101,3 +101,8 @@ pub(crate) struct DirSizes { pub(crate) numb_reg_cache_entries: u64, pub(crate) numb_reg_src_checkouts: u64, } + +fn ignore_underscore_prefix() { + let hello: (); + let _hello: (); +}