From c30967674aeb1c70b71e3aff2be47f733534538d Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 5 Dec 2020 12:40:04 -0500 Subject: [PATCH] api: remove Send bound from Arbitrary/Testable traits The Send bound is a relic from the past. Indeed, the docs for the Arbitrary trait have been outdated for quite some time. quickcheck stopped running each test in a separate thread once `std::panic::catch_unwind` was stabilized many moons ago. With `catch_unwind`, the `Send` bound is no longer necessary. We do need to retain the `'static` bound though. Without that, implementing shrink seems implausible. Fixes #262, Closes #263 --- src/arbitrary.rs | 14 ++++---------- src/tester.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/arbitrary.rs b/src/arbitrary.rs index 4693ce8..e8f0b5f 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -142,11 +142,7 @@ pub fn single_shrinker(value: A) -> Box> { /// /// As of now, all types that implement `Arbitrary` must also implement /// `Clone`. (I'm not sure if this is a permanent restriction.) -/// -/// They must also be sendable and static since every test is run in its own -/// thread using `thread::Builder::spawn`, which requires the `Send + 'static` -/// bounds. -pub trait Arbitrary: Clone + Send + 'static { +pub trait Arbitrary: Clone + 'static { fn arbitrary(g: &mut G) -> Self; fn shrink(&self) -> Box> { @@ -401,7 +397,7 @@ impl Arbitrary for BTreeMap { impl< K: Arbitrary + Eq + Hash, V: Arbitrary, - S: BuildHasher + Default + Clone + Send + 'static, + S: BuildHasher + Default + Clone + 'static, > Arbitrary for HashMap { fn arbitrary(g: &mut G) -> Self { @@ -441,10 +437,8 @@ impl Arbitrary for BinaryHeap { } } -impl< - T: Arbitrary + Eq + Hash, - S: BuildHasher + Default + Clone + Send + 'static, - > Arbitrary for HashSet +impl + Arbitrary for HashSet { fn arbitrary(g: &mut G) -> Self { let vec: Vec = Arbitrary::arbitrary(g); diff --git a/src/tester.rs b/src/tester.rs index ff66fef..491cb48 100644 --- a/src/tester.rs +++ b/src/tester.rs @@ -256,8 +256,8 @@ impl TestResult { pub fn must_fail(f: F) -> TestResult where F: FnOnce() -> T, - F: Send + 'static, - T: Send + 'static, + F: 'static, + T: 'static, { let f = panic::AssertUnwindSafe(f); TestResult::from_bool(panic::catch_unwind(f).is_err()) @@ -305,7 +305,7 @@ impl TestResult { /// and potentially shrink those arguments if they produce a failure. /// /// It's unlikely that you'll have to implement this trait yourself. -pub trait Testable: Send + 'static { +pub trait Testable: 'static { fn result(&self, _: &mut G) -> TestResult; } @@ -330,7 +330,7 @@ impl Testable for TestResult { impl Testable for Result where A: Testable, - E: Debug + Send + 'static, + E: Debug + 'static, { fn result(&self, g: &mut G) -> TestResult { match *self { @@ -409,8 +409,8 @@ testable_fn!(A, B, C, D, E, F, G, H); fn safe(fun: F) -> Result where F: FnOnce() -> T, - F: Send + 'static, - T: Send + 'static, + F: 'static, + T: 'static, { panic::catch_unwind(panic::AssertUnwindSafe(fun)).map_err(|any_err| { // Extract common types of panic payload: