Skip to content

Commit

Permalink
Lint for sum and product in consensus code (#2226)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
michaelsproul committed Mar 1, 2021
1 parent 0b2ccec commit baef1db
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions consensus/state_processing/clippy.toml
Original file line number Diff line number Diff line change
@@ -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",
]
1 change: 1 addition & 0 deletions consensus/state_processing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(clippy::integer_arithmetic)]
#![deny(clippy::disallowed_method)]

#[macro_use]
mod macros;
Expand Down
5 changes: 5 additions & 0 deletions consensus/types/clippy.toml
Original file line number Diff line number Diff line change
@@ -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",
]
1 change: 1 addition & 0 deletions consensus/types/src/beacon_state/tree_hash_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::integer_arithmetic)]
#![allow(clippy::disallowed_method)]

use super::Error;
use crate::{BeaconState, EthSpec, Hash256, Slot, Unsigned, Validator};
Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit baef1db

Please sign in to comment.