From baef1db40fd3cac414b4ee16f2035e026d316ff7 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 1 Mar 2021 00:57:13 +0000 Subject: [PATCH] Lint for sum and product in consensus code (#2226) ## Issue Addressed Closes #1621 ## Proposed Changes Use the `disallowed_method` lint to ban uses of `Iterator::{sum,product}` from `types` and `state_processing`. ## Additional Info The lint is turned off in the tree hash caching code, as it is performance sensitive and overflowy arithmetic is already allowed there. --- consensus/state_processing/clippy.toml | 5 +++++ consensus/state_processing/src/lib.rs | 1 + consensus/types/clippy.toml | 5 +++++ consensus/types/src/beacon_state/tree_hash_cache.rs | 1 + consensus/types/src/lib.rs | 1 + 5 files changed, 13 insertions(+) create mode 100644 consensus/state_processing/clippy.toml create mode 100644 consensus/types/clippy.toml diff --git a/consensus/state_processing/clippy.toml b/consensus/state_processing/clippy.toml new file mode 100644 index 000000000..e23d2ed05 --- /dev/null +++ b/consensus/state_processing/clippy.toml @@ -0,0 +1,5 @@ +# Disallow sum and product methods which are prone to overflow. +disallowed-methods = [ + "core::iter::traits::iterator::Iterator::sum", + "core::iter::traits::iterator::Iterator::product", +] diff --git a/consensus/state_processing/src/lib.rs b/consensus/state_processing/src/lib.rs index 4a04c0244..3ae90f885 100644 --- a/consensus/state_processing/src/lib.rs +++ b/consensus/state_processing/src/lib.rs @@ -1,4 +1,5 @@ #![deny(clippy::integer_arithmetic)] +#![deny(clippy::disallowed_method)] #[macro_use] mod macros; diff --git a/consensus/types/clippy.toml b/consensus/types/clippy.toml new file mode 100644 index 000000000..e23d2ed05 --- /dev/null +++ b/consensus/types/clippy.toml @@ -0,0 +1,5 @@ +# Disallow sum and product methods which are prone to overflow. +disallowed-methods = [ + "core::iter::traits::iterator::Iterator::sum", + "core::iter::traits::iterator::Iterator::product", +] diff --git a/consensus/types/src/beacon_state/tree_hash_cache.rs b/consensus/types/src/beacon_state/tree_hash_cache.rs index ddd85bb93..ee8cfb2dd 100644 --- a/consensus/types/src/beacon_state/tree_hash_cache.rs +++ b/consensus/types/src/beacon_state/tree_hash_cache.rs @@ -1,4 +1,5 @@ #![allow(clippy::integer_arithmetic)] +#![allow(clippy::disallowed_method)] use super::Error; use crate::{BeaconState, EthSpec, Hash256, Slot, Unsigned, Validator}; diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index be86daad5..5016b6f13 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -4,6 +4,7 @@ #![recursion_limit = "128"] // Clippy lint set up #![deny(clippy::integer_arithmetic)] +#![deny(clippy::disallowed_method)] #[macro_use] extern crate lazy_static;