Skip to content

Commit

Permalink
Auto merge of #11552 - jonboh:ice_threshold_0_enum_variants, r=y21
Browse files Browse the repository at this point in the history
prevent ice when threshold is 0 and enum has no variants

changelog: [`enum_variant_names`]: prevent ice when threshold is 0 and enum has no variants

r? `@y21`

Fixes the same ice issue raised during review of #11496
  • Loading branch information
bors committed Sep 24, 2023
2 parents 94fc431 + 0433e45 commit aa137a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/ui-toml/enum_variants_threshold0/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum-variant-name-threshold = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum Actions {}

fn main() {}

0 comments on commit aa137a7

Please sign in to comment.