diff options
| author | bors <bors@rust-lang.org> | 2021-01-22 23:44:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-22 23:44:12 +0000 |
| commit | 70386ff352cd08b29e1810c098a8e73ee20b7770 (patch) | |
| tree | 2a586e37a2360e471d33ae30b5aa9a371ed87ce9 | |
| parent | 41d750c76ca04be143ce792d3edcb291b8ca885f (diff) | |
| parent | f2d493504cb863a30f45e8a0d5717285823f931e (diff) | |
| download | rust-70386ff352cd08b29e1810c098a8e73ee20b7770.tar.gz rust-70386ff352cd08b29e1810c098a8e73ee20b7770.zip | |
Auto merge of #6403 - camsteffen:similar-names-underscore, r=Manishearth
Similar names ignore underscore prefixed names changelog: Ignore underscore-prefixed names for similar_names IMO, this lint is not very helpful for underscore-prefixed variables. Usually they are unused or are just there to ignore part of a destructuring.
| -rw-r--r-- | clippy_lints/src/non_expressive_names.rs | 4 | ||||
| -rw-r--r-- | tests/ui/similar_names.rs | 5 |
2 files changed, 9 insertions, 0 deletions
diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 446426b3e61..855529378e6 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 6796b15289e..5981980988b 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: (); +} |
