about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/enum_variants.rs5
-rw-r--r--tests/ui-toml/enum_variants_threshold0/clippy.toml1
-rw-r--r--tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs3
3 files changed, 8 insertions, 1 deletions
diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs
index d4df6f7aa2d..e332f681b6d 100644
--- a/clippy_lints/src/enum_variants.rs
+++ b/clippy_lints/src/enum_variants.rs
@@ -167,7 +167,10 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
         return;
     }
 
-    let first = &def.variants[0].ident.name.as_str();
+    let first = match def.variants.first() {
+        Some(variant) => variant.ident.name.as_str(),
+        None => return,
+    };
     let mut pre = camel_case_split(first);
     let mut post = pre.clone();
     post.reverse();
diff --git a/tests/ui-toml/enum_variants_threshold0/clippy.toml b/tests/ui-toml/enum_variants_threshold0/clippy.toml
new file mode 100644
index 00000000000..f85aade6ae8
--- /dev/null
+++ b/tests/ui-toml/enum_variants_threshold0/clippy.toml
@@ -0,0 +1 @@
+enum-variant-name-threshold = 0
diff --git a/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs b/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs
new file mode 100644
index 00000000000..6918d7528c1
--- /dev/null
+++ b/tests/ui-toml/enum_variants_threshold0/enum_variants_name_threshold.rs
@@ -0,0 +1,3 @@
+enum Actions {}
+
+fn main() {}