From aac8370f7563f2da9d9e7614fe50b6c3a00daba7 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Sun, 10 Nov 2024 22:58:56 +0000 Subject: [PATCH] Improve check script to allow running just some checks. --- .github/workflows/ci.yml | 19 +++++- .taplo.toml | 17 +++++ Cargo.toml | 16 ++--- benches/std_btree_map.rs | 1 + benches/std_hash_map.rs | 1 + src/list/mod.rs | 2 +- src/map/hash_trie_map/mod.rs | 3 +- src/map/hash_trie_map/test.rs | 4 ++ src/map/red_black_tree_map/test.rs | 4 ++ src/set/hash_trie_set/mod.rs | 1 + src/vector/test.rs | 4 ++ tools/check.sh | 106 ++++++++++++++++++++++------- 12 files changed, 137 insertions(+), 41 deletions(-) create mode 100644 .taplo.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e13c23..586a109 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,13 +28,15 @@ jobs: - name: Install cargo plugins run: | cargo install cargo-rdme + cargo install cargo-machete + cargo install taplo-cli cargo install cargo-deadlinks - name: Checkout repository uses: actions/checkout@v4 - name: Check everything - run: bash ./tools/check.sh + run: bash ./tools/check.sh basic doc_url_links unused_deps packaging fmt toml_fmt readme - name: Code coverage if: ${{ runner.os == 'Linux' }} @@ -57,4 +59,17 @@ jobs: uses: actions/checkout@v4 - name: Check the minimum supported rust version - run: cargo msrv verify + run: bash ./tools/check.sh msrv + + clippy: + runs-on: ubuntu-latest + + steps: + - name: Install rust + uses: dtolnay/rust-toolchain@stable + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run clippy + run: bash ./tools/check.sh clippy diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 0000000..6ca9d28 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,17 @@ +include = ["**/*.toml"] +exclude = ["target/**"] + +[formatting] +column_width = 100 +indent_string = ' ' +allowed_blank_lines = 1 + +[[rule]] +formatting = { reorder_keys = true } +keys = [ + "workspace.dependencies", + "dependencies", + "dev-dependencies", + "build-dependencies", + "lints.clippy", +] diff --git a/Cargo.toml b/Cargo.toml index 1278927..e0f5172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,16 +12,8 @@ repository = "https://github.com/orium/rpds" documentation = "https://docs.rs/rpds" readme = "README.md" -keywords = [ - "data-structure", - "data-structures", - "persistent", - "immutable", - "no_std" -] -categories = [ - "data-structures", -] +keywords = ["data-structure", "data-structures", "persistent", "immutable", "no_std"] +categories = ["data-structures"] license = "MPL-2.0" @@ -57,8 +49,8 @@ std = [] [lints.clippy] all = { level = "warn", priority = -2 } -pedantic = { level = "warn", priority = -2 } correctness = { level = "deny", priority = -1 } +pedantic = { level = "warn", priority = -2 } enum-glob-use = "allow" if-not-else = "allow" @@ -66,8 +58,10 @@ match-bool = "allow" match-same-arms = "allow" missing-panics-doc = "allow" module-name-repetitions = "allow" +multiple-bound-locations = "allow" similar-names = "allow" single-match-else = "allow" +struct-field-names = "allow" type-complexity = "allow" type-repetition-in-bounds = "allow" unnested-or-patterns = "allow" diff --git a/benches/std_btree_map.rs b/benches/std_btree_map.rs index 440c3ca..8f6dd71 100644 --- a/benches/std_btree_map.rs +++ b/benches/std_btree_map.rs @@ -4,6 +4,7 @@ */ #![cfg_attr(feature = "fatal-warnings", deny(warnings))] +#![allow(clippy::cast_possible_wrap)] use criterion::{criterion_group, criterion_main, Criterion}; use std::collections::BTreeMap; diff --git a/benches/std_hash_map.rs b/benches/std_hash_map.rs index a920fdf..6c21c9a 100644 --- a/benches/std_hash_map.rs +++ b/benches/std_hash_map.rs @@ -4,6 +4,7 @@ */ #![cfg_attr(feature = "fatal-warnings", deny(warnings))] +#![allow(clippy::cast_possible_wrap)] use criterion::{criterion_group, criterion_main, Criterion}; use std::collections::HashMap; diff --git a/src/list/mod.rs b/src/list/mod.rs index cf4e611..7cf048c 100644 --- a/src/list/mod.rs +++ b/src/list/mod.rs @@ -185,7 +185,7 @@ where pub fn drop_first_mut(&mut self) -> bool { self.head.take().map_or(false, |h| { - self.head = h.next.clone(); + self.head.clone_from(&h.next); self.length -= 1; if self.length == 0 { diff --git a/src/map/hash_trie_map/mod.rs b/src/map/hash_trie_map/mod.rs index 7cb8f45..b03e323 100644 --- a/src/map/hash_trie_map/mod.rs +++ b/src/map/hash_trie_map/mod.rs @@ -236,7 +236,7 @@ mod node_utils { } pub fn hash(v: &T, hasher_builder: &H) -> HashValue { - hasher_builder.hash_one(&v) + hasher_builder.hash_one(v) } } @@ -873,6 +873,7 @@ where self.size() == 0 } + #[allow(clippy::iter_without_into_iter)] pub fn iter(&self) -> Iter<'_, K, V, P> { self.iter_ptr().map(|e| (&e.key, &e.value)) } diff --git a/src/map/hash_trie_map/test.rs b/src/map/hash_trie_map/test.rs index 21d03dc..783b513 100644 --- a/src/map/hash_trie_map/test.rs +++ b/src/map/hash_trie_map/test.rs @@ -3,6 +3,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#![allow(clippy::cast_possible_truncation)] +#![allow(clippy::cast_possible_wrap)] +#![allow(clippy::cast_sign_loss)] + use super::*; use pretty_assertions::assert_eq; use static_assertions::assert_impl_all; diff --git a/src/map/red_black_tree_map/test.rs b/src/map/red_black_tree_map/test.rs index eced735..263c2ca 100644 --- a/src/map/red_black_tree_map/test.rs +++ b/src/map/red_black_tree_map/test.rs @@ -3,6 +3,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#![allow(clippy::cast_possible_truncation)] +#![allow(clippy::cast_possible_wrap)] +#![allow(clippy::cast_sign_loss)] + use super::*; use alloc::vec::Vec; use pretty_assertions::assert_eq; diff --git a/src/set/hash_trie_set/mod.rs b/src/set/hash_trie_set/mod.rs index 92f99ca..f603f99 100644 --- a/src/set/hash_trie_set/mod.rs +++ b/src/set/hash_trie_set/mod.rs @@ -247,6 +247,7 @@ where self.size() == 0 } + #[allow(clippy::iter_without_into_iter)] pub fn iter(&self) -> Iter<'_, T, P> { self.map.keys() } diff --git a/src/vector/test.rs b/src/vector/test.rs index 87c6080..0834ba7 100644 --- a/src/vector/test.rs +++ b/src/vector/test.rs @@ -3,6 +3,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#![allow(clippy::cast_possible_truncation)] +#![allow(clippy::cast_possible_wrap)] +#![allow(clippy::cast_sign_loss)] + use super::*; use alloc::string::String; use pretty_assertions::assert_eq; diff --git a/tools/check.sh b/tools/check.sh index 776627c..5b478b5 100755 --- a/tools/check.sh +++ b/tools/check.sh @@ -20,35 +20,89 @@ function on_failure { echo -e "${RED}Whoopsie-daisy: something failed!$NC" >&2 } -assert_installed "cargo-deadlinks" -assert_installed "cargo-fmt" -assert_installed "cargo-rdme" +assert_installed "cargo" trap on_failure ERR -echo 'Building:' -# Run check with no default features to check `no_std`. -cargo check --no-default-features --features fatal-warnings,serde --all-targets -cargo build --features fatal-warnings,serde --all-targets -echo 'Testing:' -cargo test --features fatal-warnings,serde --all-targets --benches -# Weirdly, the `cargo test ... --all-targets ...` above does not run the tests in the documentation, so we run the -# doc tests like this. -# See https://github.com/rust-lang/cargo/issues/6669. -echo 'Testing doc:' -cargo test --features fatal-warnings,serde --doc -echo 'Checking documentation:' -cargo doc --features fatal-warnings,serde --no-deps --document-private-items - -echo 'Checking links:' -cargo deadlinks - -echo 'Checking packaging:' -cargo package --allow-dirty -echo 'Checking code style:' -cargo fmt -- --check -echo 'Checking readme:' -cargo rdme --check +function check_basic { + echo 'Building:' + cargo build --features fatal-warnings --all-targets + echo 'Testing:' + cargo test --features fatal-warnings --all-targets + # Weirdly, the `cargo test ... --all-targets ...` above does not run the tests in the documentation, so we run the + # doc tests like this. + # See https://github.com/rust-lang/cargo/issues/6669. + echo 'Testing doc:' + cargo test --features fatal-warnings --doc + echo 'Checking the benchmarks:' + cargo bench --features fatal-warnings -- --test + echo 'Checking documentation:' + cargo doc --features fatal-warnings --no-deps +} + +function check_doc_url_links { + assert_installed "cargo-deadlinks" + + echo 'Checking doc url links:' + cargo deadlinks +} + +function check_unused_deps { + assert_installed "cargo-machete" + + echo 'Checking unused dependencies:' + cargo machete +} + +function check_packaging { + echo 'Checking packaging:' + cargo package --allow-dirty +} + +function check_fmt { + assert_installed "cargo-fmt" + + echo 'Checking code format:' + cargo fmt -- --check +} + +function check_toml_fmt { + assert_installed "taplo" + + echo 'Checking toml format:' + taplo fmt --check +} + +function check_readme { + assert_installed "cargo-rdme" + + echo 'Checking readme:' + cargo rdme --check +} + +function check_msrv { + assert_installed "cargo-msrv" + + echo 'Checking the minimum supported rust version:' + cargo msrv verify +} + +function check_clippy { + assert_installed "cargo-clippy" + + echo 'Checking with clippy:' + cargo clippy --all-targets -- -D warnings +} + +to_run=(basic doc_url_links unused_deps packaging fmt toml_fmt readme msrv clippy) + +if [ $# -ge 1 ]; then + to_run=("$@") +fi + +for check in "${to_run[@]}"; do + check_$check +done echo echo -e "${GREEN}Everything looks lovely!$NC"