diff options
| author | kraktus <kraktus@users.noreply.github.com> | 2022-10-23 14:00:44 +0200 |
|---|---|---|
| committer | kraktus <kraktus@users.noreply.github.com> | 2022-11-07 19:49:43 +0100 |
| commit | 586bd3f735a7ec8c0ee03ab3515dfd8a89a31ff4 (patch) | |
| tree | 79c48c110c7ef017626b09d408fe8bcfe4f66f91 | |
| parent | cca9938694eff5a2f4c2731966a9dd8ce4b118e7 (diff) | |
| download | rust-586bd3f735a7ec8c0ee03ab3515dfd8a89a31ff4.tar.gz rust-586bd3f735a7ec8c0ee03ab3515dfd8a89a31ff4.zip | |
refactor to avoid potential ICE
| -rw-r--r-- | clippy_lints/src/excessive_bools.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/clippy_lints/src/excessive_bools.rs b/clippy_lints/src/excessive_bools.rs index 453471c8cdd..e1911449242 100644 --- a/clippy_lints/src/excessive_bools.rs +++ b/clippy_lints/src/excessive_bools.rs @@ -141,14 +141,13 @@ impl EarlyLintPass for ExcessiveBools { return; } - let struct_bools = variant_data + if let Ok(struct_bools) = variant_data .fields() .iter() .filter(|field| is_bool_ty(&field.ty)) .count() - .try_into() - .unwrap(); - if self.max_struct_bools < struct_bools { + .try_into() && self.max_struct_bools < struct_bools + { span_lint_and_help( cx, STRUCT_EXCESSIVE_BOOLS, @@ -156,8 +155,8 @@ impl EarlyLintPass for ExcessiveBools { &format!("more than {} bools in a struct", self.max_struct_bools), None, "consider using a state machine or refactoring bools into two-variant enums", - ); - } + ) + } }, ItemKind::Impl(box Impl { of_trait: None, items, .. |
