about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-06-26 16:11:06 +0000
committerbors <bors@rust-lang.org>2022-06-26 16:11:06 +0000
commit9b150625a930cd7e0a72a071dd8c1127b5bec451 (patch)
treed0fb353bb8ebbcfaa665f2f0b71a4df7da291aff /clippy_lints
parentab58276146c652136ece8b5635d5f2f3776646d4 (diff)
parentd827b834d91383620d587fb4a1e74d8579e3a280 (diff)
downloadrust-9b150625a930cd7e0a72a071dd8c1127b5bec451.tar.gz
rust-9b150625a930cd7e0a72a071dd8c1127b5bec451.zip
Auto merge of #9032 - kyoto7250:issue_9018, r=llogiq
enum_variant_names should ignore when all prefixes are _

close #9018

When Enum prefix is only an underscore, we should not issue warnings.

changelog: fix false positive in enum_variant_names
Diffstat (limited to 'clippy_lints')
-rw-r--r--clippy_lints/src/enum_variants.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs
index 23b75104570..cd36f9fcd72 100644
--- a/clippy_lints/src/enum_variants.rs
+++ b/clippy_lints/src/enum_variants.rs
@@ -190,7 +190,7 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
             .map(|e| *e.0)
             .collect();
     }
-    let (what, value) = match (pre.is_empty(), post.is_empty()) {
+    let (what, value) = match (have_no_extra_prefix(&pre), post.is_empty()) {
         (true, true) => return,
         (false, _) => ("pre", pre.join("")),
         (true, false) => {
@@ -213,6 +213,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
 }
 
 #[must_use]
+fn have_no_extra_prefix(prefixes: &[&str]) -> bool {
+    prefixes.iter().all(|p| p == &"" || p == &"_")
+}
+
+#[must_use]
 fn to_camel_case(item_name: &str) -> String {
     let mut s = String::new();
     let mut up = true;