diff --git a/.githooks/pre-commit b/.githooks/pre-commit index ab3e81f1a..6b884fc62 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,7 +3,6 @@ set -eux ./scripts/fmt.sh --pre-commit -./scripts/hash.sh --pre-commit ./scripts/clippy.sh --pre-commit ./scripts/documentation.sh --pre-commit ./scripts/deny.sh --pre-commit diff --git a/pumpkin-crates/core/clippy.toml b/pumpkin-crates/core/clippy.toml new file mode 100644 index 000000000..9d3ca24f5 --- /dev/null +++ b/pumpkin-crates/core/clippy.toml @@ -0,0 +1,7 @@ +disallowed-types = [ + { path = "std::collections::HashSet", reason = "use pumpkin_solver::containers::HashSet" }, + { path = "std::collections::HashMap", reason = "use pumpkin_solver::containers::HashMap" }, + { path = "rand::RngCore", reason = "use pumpkin_solver::basic_types::Random" }, + { path = "rand::Rng", reason = "use pumpkin_solver::basic_types::Random" }, + { path = "rand::SeedableRng", reason = "use pumpkin_solver::basic_types::Random" }, +] diff --git a/pumpkin-crates/core/src/basic_types/random.rs b/pumpkin-crates/core/src/basic_types/random.rs index 2ce8744ef..7786fe708 100644 --- a/pumpkin-crates/core/src/basic_types/random.rs +++ b/pumpkin-crates/core/src/basic_types/random.rs @@ -1,7 +1,15 @@ use std::fmt::Debug; use std::ops::Range; +#[allow( + clippy::disallowed_types, + reason = "we implement our random generator using rand" +)] use rand::Rng; +#[allow( + clippy::disallowed_types, + reason = "we implement our random generator using rand" +)] use rand::SeedableRng; use crate::pumpkin_assert_moderate; @@ -74,6 +82,10 @@ pub trait Random: Debug { // We provide a blanket implementation of the trait for any type which implements `SeedableRng`, // `Rng` and `Debug` to ensure that we can use any "regular" random generator where we expect an // implementation of Random. +#[allow( + clippy::disallowed_types, + reason = "we implement our random generator using rand" +)] impl Random for T where T: SeedableRng + Rng + Debug, diff --git a/pumpkin-crates/core/src/containers/mod.rs b/pumpkin-crates/core/src/containers/mod.rs index 0bfc82666..f0abaef64 100644 --- a/pumpkin-crates/core/src/containers/mod.rs +++ b/pumpkin-crates/core/src/containers/mod.rs @@ -11,6 +11,8 @@ pub use keyed_vec::*; pub(crate) use sparse_set::*; /// [`std::collections::HashMap`] that defaults to a deterministic hasher. +#[allow(clippy::disallowed_types, reason = "this is how we define our HashMap")] pub type HashMap = std::collections::HashMap; /// [`std::collections::HashSet`] that defaults to a deterministic hasher. +#[allow(clippy::disallowed_types, reason = "this is how we define our HashSet")] pub type HashSet = std::collections::HashSet; diff --git a/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs b/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs index 9d75a5b14..a05b076f0 100644 --- a/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs +++ b/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs @@ -5,6 +5,10 @@ use std::collections::VecDeque; use std::fmt::Debug; use std::time::Instant; +#[allow( + clippy::disallowed_types, + reason = "any rand generator is a valid implementation of Random" +)] use rand::SeedableRng; use rand::rngs::SmallRng; diff --git a/scripts/hash.sh b/scripts/hash.sh deleted file mode 100755 index 66b988005..000000000 --- a/scripts/hash.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -ux - -results=$(grep --recursive --files-with-matches --exclude="hash_structures.rs" --fixed-strings 'std::collections::Hash' ./pumpkin-lib/) -num_results=$(echo "$results" | wc --lines) -if [ "$results" != "" ]; then - echo -e "\033[0;31mHash-based structures from the standard library found in file(s):\n$results\033[0m" - echo -e "\033[0;31mPlease do not used hash-based structures from the standard library, hash-based structures in Rust do not provide any guarantees on the order which leads to poor reproducibility (see /pumpkin-lib/src/basic_types/hash_structures.rs)\033[0m" - exit 1 -else - exit 0 -fi \ No newline at end of file