Skip to content

Commit a3c482e

Browse files
committed
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.
1 parent 668e904 commit a3c482e

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Disallow sum and product methods which are prone to overflow.
2+
disallowed-methods = [
3+
"core::iter::traits::iterator::Iterator::sum",
4+
"core::iter::traits::iterator::Iterator::product",
5+
]

consensus/state_processing/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(clippy::integer_arithmetic)]
2+
#![deny(clippy::disallowed_method)]
23

34
#[macro_use]
45
mod macros;

consensus/types/clippy.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Disallow sum and product methods which are prone to overflow.
2+
disallowed-methods = [
3+
"core::iter::traits::iterator::Iterator::sum",
4+
"core::iter::traits::iterator::Iterator::product",
5+
]

consensus/types/src/beacon_state/tree_hash_cache.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(clippy::integer_arithmetic)]
2+
#![allow(clippy::disallowed_method)]
23

34
use super::Error;
45
use crate::{BeaconState, EthSpec, Hash256, Slot, Unsigned, Validator};

consensus/types/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![recursion_limit = "128"]
55
// Clippy lint set up
66
#![deny(clippy::integer_arithmetic)]
7+
#![deny(clippy::disallowed_method)]
78

89
#[macro_use]
910
extern crate lazy_static;

0 commit comments

Comments
 (0)