From b8d43badfe8eca7d99580b91f5a226a57dfbc310 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 9 Feb 2019 16:56:27 +0000 Subject: [PATCH 1/7] Use strum::EnumCount to derive Op counts --- Cargo.toml | 2 ++ src/lib.rs | 5 ++++- src/stdlib/collections/hash_map.rs | 10 ++-------- src/stdlib/collections/vec_deque.rs | 10 ++-------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47b7d13..9548edf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,8 @@ authors = ["Brian L. Troutwine "] afl = "0.4" arbitrary = "0.2" bh_alloc = "0.1" +strum = "0.13.0" +strum_macros = "0.13.0" [[bin]] path = "src/bin/stdlib/str/repeat.rs" diff --git a/src/lib.rs b/src/lib.rs index 7d3ba64..40f1266 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,10 @@ extern crate arbitrary; +extern crate strum; +#[macro_use] +extern crate strum_macros; #[deny(warnings)] #[deny(bad_style)] -#[deny(missing_docs)] +#[allow(missing_docs)] #[deny(future_incompatible)] #[deny(nonstandard_style)] #[deny(rust_2018_compatibility)] diff --git a/src/stdlib/collections/hash_map.rs b/src/stdlib/collections/hash_map.rs index aebe34d..1a1e04e 100644 --- a/src/stdlib/collections/hash_map.rs +++ b/src/stdlib/collections/hash_map.rs @@ -157,7 +157,7 @@ where /// `HashMap` and `PropHashMap`. Some map directly to functions /// available on the types, others require a more elaborate interpretation /// step. -#[derive(Clone, Debug)] +#[derive(Clone, EnumCount, Debug)] pub enum Op { /// This operation triggers `std::collections::HashMap::shrink_to_fit` ShrinkToFit, @@ -196,13 +196,7 @@ where where U: Unstructured + ?Sized, { - // ================ WARNING ================ - // - // `total_enum_fields` is a goofy annoyance but it should match - // _exactly_ the number of fields available in `Op`. If it - // does not then we'll fail to generate `Op` variants for use in our - // QC tests. - let total_enum_fields = 6; + let total_enum_fields = OP_COUNT as u8; let variant: u8 = Arbitrary::arbitrary(u)?; let op = match variant % total_enum_fields { 0 => { diff --git a/src/stdlib/collections/vec_deque.rs b/src/stdlib/collections/vec_deque.rs index fb3aa0d..272a175 100644 --- a/src/stdlib/collections/vec_deque.rs +++ b/src/stdlib/collections/vec_deque.rs @@ -143,7 +143,7 @@ impl PropVecDeque { /// The `Op` defines the set of operations that are available against /// `VecDeque` and `PropVecDeque`. Some map directly to functions /// available on the types, others require a more elaborate interpretation step. -#[derive(Clone, Debug)] +#[derive(Clone, EnumCount, Debug)] pub enum Op { /// This operation triggers `std::collections::VecDeque::shrink_to_fit` ShrinkToFit, @@ -173,13 +173,7 @@ where where U: Unstructured + ?Sized, { - // ================ WARNING ================ - // - // `total_enum_fields` is a goofy annoyance but it should match - // _exactly_ the number of fields available in `Op`. If it - // does not then we'll fail to generate `Op` variants for use in our - // QC tests. - let total_enum_fields = 9; + let total_enum_fields = OP_COUNT as u8; let variant: u8 = Arbitrary::arbitrary(u)?; let op = match variant % total_enum_fields { 0 => { From 9a4924ff7ecb8d48f70fa2a83dbb8b7f741e097d Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 9 Feb 2019 20:49:39 +0000 Subject: [PATCH 2/7] Switch to non-preview rustfmt/clippy --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e925be0..3f5a45a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: include: - rust: stable before_script: - - rustup component add rustfmt-preview + - rustup component add rustfmt script: - cargo fmt -- --check - cargo test @@ -25,7 +25,7 @@ matrix: - cargo test --release - rust: nightly before_script: - - rustup component add clippy-preview + - rustup component add clippy script: - cargo clippy - cargo test From 46bd69e879e3d958841bcd536cbfc30155a6194a Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 10 Feb 2019 10:26:50 +0000 Subject: [PATCH 3/7] Clippy won't always be available on nightly --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f5a45a..0029874 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,10 +24,7 @@ matrix: script: - cargo test --release - rust: nightly - before_script: - - rustup component add clippy script: - - cargo clippy - cargo test - rust: nightly script: From b27e3fa9db71397b043f55de0680b3fa2c2237c2 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 10 Feb 2019 10:31:14 +0000 Subject: [PATCH 4/7] Switch to modified strum_macros --- Cargo.toml | 3 +++ src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9548edf..5322076 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,6 @@ name = "hash_map" [[bin]] path = "src/bin/stdlib/collections/vec_deque.rs" name = "vec_deque" + +[patch.crates-io] +strum_macros = { git = "https://github.com/dwijnand/strum", branch = "enum_count_docs" } diff --git a/src/lib.rs b/src/lib.rs index 40f1266..88d067b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ extern crate strum; extern crate strum_macros; #[deny(warnings)] #[deny(bad_style)] -#[allow(missing_docs)] +#[deny(missing_docs)] #[deny(future_incompatible)] #[deny(nonstandard_style)] #[deny(rust_2018_compatibility)] From b1bbb6e5aafbf155822c11edc33fd0630de0fb8d Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 10 Feb 2019 10:32:45 +0000 Subject: [PATCH 5/7] Add clippy (back) on the stable channel --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0029874..735c022 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,10 @@ matrix: - rust: stable before_script: - rustup component add rustfmt + - rustup component add clippy script: - cargo fmt -- --check + - cargo clippy - cargo test - rust: stable script: From fa3c6bf9024a30e8eb8b6635158073af1ad40dbc Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 10 Feb 2019 11:13:34 +0000 Subject: [PATCH 6/7] Allow stable clippy to run by updating bh_alloc Previous bh_alloc used "feature(tool_lints)" which is nightly only. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5322076..2bfb493 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Brian L. Troutwine "] [dependencies] afl = "0.4" arbitrary = "0.2" -bh_alloc = "0.1" +bh_alloc = "0.2.4" strum = "0.13.0" strum_macros = "0.13.0" From 6379668e67a1f0d698a8c704aeeb95b84fa42bc2 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 18 Feb 2019 21:02:52 +0000 Subject: [PATCH 7/7] Switch to upstream strum_macros, now that my PR is merged --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2bfb493..574d88c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ path = "src/bin/stdlib/collections/vec_deque.rs" name = "vec_deque" [patch.crates-io] -strum_macros = { git = "https://github.com/dwijnand/strum", branch = "enum_count_docs" } +strum_macros = { git = "https://github.com/Peternator7/strum" }