Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

Use strum::EnumCount to derive Op counts #13

Merged
merged 7 commits into from Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -7,6 +7,8 @@ authors = ["Brian L. Troutwine <brian@troutwine.us>"]
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"
Expand Down
5 changes: 4 additions & 1 deletion 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)]
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
#[allow(missing_docs)]
#[deny(future_incompatible)]
#[deny(nonstandard_style)]
#[deny(rust_2018_compatibility)]
Expand Down
10 changes: 2 additions & 8 deletions src/stdlib/collections/hash_map.rs
Expand Up @@ -157,7 +157,7 @@ where
/// `HashMap<K, V>` and `PropHashMap<K, V>`. 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<K, V> {
/// This operation triggers `std::collections::HashMap::shrink_to_fit`
ShrinkToFit,
Expand Down Expand Up @@ -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<K, V>`. 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;
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
let variant: u8 = Arbitrary::arbitrary(u)?;
let op = match variant % total_enum_fields {
0 => {
Expand Down
10 changes: 2 additions & 8 deletions src/stdlib/collections/vec_deque.rs
Expand Up @@ -143,7 +143,7 @@ impl<T> PropVecDeque<T> {
/// The `Op<T>` defines the set of operations that are available against
/// `VecDeque<K, V>` and `PropVecDeque<T>`. 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<T> {
/// This operation triggers `std::collections::VecDeque::shrink_to_fit`
ShrinkToFit,
Expand Down Expand Up @@ -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<T>`. 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 => {
Expand Down