Skip to content

Commit

Permalink
[Fix] NonZero : only impl Arbitrary for 128-bit NonZero nums in non-w…
Browse files Browse the repository at this point in the history
…asm targets (#322)
  • Loading branch information
matthew-russo committed May 20, 2023
1 parent 0b2628c commit 18ca1af
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions proptest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Bug Fixes

- Don't implement Arbitrary for NonZeroU128 and NonZeroI128 on wasm targets where
u128 and i128 Arbitrary impls don't exist

### New Features

### Other Notes
Expand Down
1 change: 1 addition & 0 deletions proptest/src/arbitrary/_core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod fmt;
mod iter;
mod marker;
mod mem;
mod non_zero;
mod num;
mod option;
mod result;
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
// except according to those terms.

use core::convert::TryFrom;
#[cfg(not(target_arch = "wasm32"))]
use core::num::{NonZeroI128, NonZeroU128};
use core::num::{
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize,
NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU16,
NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
};

use crate::arbitrary::{any, Arbitrary, StrategyFor};
use crate::strategy::{FilterMap, Strategy};

use super::{any, Arbitrary, StrategyFor};

macro_rules! non_zero_impl {
($nz:ty, $prim:ty) => {
impl Arbitrary for $nz {
Expand All @@ -37,13 +38,15 @@ non_zero_impl!(NonZeroU8, u8);
non_zero_impl!(NonZeroU16, u16);
non_zero_impl!(NonZeroU32, u32);
non_zero_impl!(NonZeroU64, u64);
#[cfg(not(target_arch = "wasm32"))]
non_zero_impl!(NonZeroU128, u128);
non_zero_impl!(NonZeroUsize, usize);

non_zero_impl!(NonZeroI8, i8);
non_zero_impl!(NonZeroI16, i16);
non_zero_impl!(NonZeroI32, i32);
non_zero_impl!(NonZeroI64, i64);
#[cfg(not(target_arch = "wasm32"))]
non_zero_impl!(NonZeroI128, i128);
non_zero_impl!(NonZeroIsize, isize);

Expand All @@ -54,13 +57,16 @@ mod test {
u16 => core::num::NonZeroU16,
u32 => core::num::NonZeroU32,
u64 => core::num::NonZeroU64,
u128 => core::num::NonZeroU128,
usize => core::num::NonZeroUsize,
i8 => core::num::NonZeroI8,
i16 => core::num::NonZeroI16,
i32 => core::num::NonZeroI32,
i64 => core::num::NonZeroI64,
i128 => core::num::NonZeroI128,
isize => core::num::NonZeroIsize
);
#[cfg(not(target_arch = "wasm32"))]
no_panic_test!(
u128 => core::num::NonZeroU128,
i128 => core::num::NonZeroI128
);
}
1 change: 0 additions & 1 deletion proptest/src/arbitrary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub mod functor;
mod macros;

mod arrays;
mod non_zero;
mod primitives;
mod sample;
mod tuples;
Expand Down
2 changes: 1 addition & 1 deletion proptest/src/test_runner/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<T: fmt::Debug> fmt::Display for TestError<T> {
TestError::Fail(ref why, ref what) => {
writeln!(f, "Test failed: {}.", why)?;
write!(f, "minimal failing input: {:#?}", what)
},
}
}
}
}
Expand Down

0 comments on commit 18ca1af

Please sign in to comment.