|
0 |
From 3544f3612448a2222f72dbd2c45d3dc5dbe64083 Mon Sep 17 00:00:00 2001
|
|
1 |
From: Jim Turner <git@turner.link>
|
|
2 |
Date: Mon, 14 Oct 2019 17:30:12 -0400
|
|
3 |
Subject: [PATCH] Update to rand 0.7
|
|
4 |
|
|
5 |
---
|
|
6 |
proptest/CHANGELOG.md | 6 ++++++
|
|
7 |
proptest/Cargo.toml | 8 +++----
|
|
8 |
proptest/src/test_runner/rng.rs | 37 ++++++++++++++++++++++++++++-----
|
|
9 |
3 files changed, 42 insertions(+), 9 deletions(-)
|
|
10 |
|
|
11 |
diff --git a/src/test_runner/rng.rs b/src/test_runner/rng.rs
|
|
12 |
index 7b1dba1..44522af 100644
|
|
13 |
--- a/src/test_runner/rng.rs
|
|
14 |
+++ b/src/test_runner/rng.rs
|
|
15 |
@@ -115,6 +115,37 @@ enum TestRngImpl {
|
|
16 |
},
|
|
17 |
}
|
|
18 |
|
|
19 |
+/// Error indicating that the `PassThrough` RNG ran out of data.
|
|
20 |
+#[derive(Debug, Clone)]
|
|
21 |
+struct PassThroughExhaustedError;
|
|
22 |
+
|
|
23 |
+impl PassThroughExhaustedError {
|
|
24 |
+ /// Error code representing this error for `no_std` (instead of boxing the error).
|
|
25 |
+ #[allow(unused)]
|
|
26 |
+ pub const ERROR_CODE: u32 = rand::Error::CUSTOM_START + 0x35e43220;
|
|
27 |
+}
|
|
28 |
+
|
|
29 |
+impl fmt::Display for PassThroughExhaustedError {
|
|
30 |
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
31 |
+ write!(f, "out of PassThrough data")
|
|
32 |
+ }
|
|
33 |
+}
|
|
34 |
+
|
|
35 |
+#[cfg(feature = "std")]
|
|
36 |
+impl std::error::Error for PassThroughExhaustedError {}
|
|
37 |
+
|
|
38 |
+impl From<PassThroughExhaustedError> for rand::Error {
|
|
39 |
+ fn from(err: PassThroughExhaustedError) -> rand::Error {
|
|
40 |
+ #[cfg(feature = "std")]
|
|
41 |
+ return rand::Error::new(err);
|
|
42 |
+ #[cfg(not(feature = "std"))]
|
|
43 |
+ return rand::Error::from(
|
|
44 |
+ core::num::NonZeroU32::new(PassThroughExhaustedError::ERROR_CODE)
|
|
45 |
+ .unwrap(),
|
|
46 |
+ );
|
|
47 |
+ }
|
|
48 |
+}
|
|
49 |
+
|
|
50 |
impl RngCore for TestRng {
|
|
51 |
fn next_u32(&mut self) -> u32 {
|
|
52 |
match &mut self.rng {
|
|
53 |
@@ -174,10 +205,7 @@ impl RngCore for TestRng {
|
|
54 |
ref data,
|
|
55 |
} => {
|
|
56 |
if *off + dest.len() > end {
|
|
57 |
- return Err(rand::Error::new(
|
|
58 |
- rand::ErrorKind::Unavailable,
|
|
59 |
- "out of PassThrough data",
|
|
60 |
- ));
|
|
61 |
+ return Err(rand::Error::from(PassThroughExhaustedError));
|
|
62 |
}
|
|
63 |
|
|
64 |
dest.copy_from_slice(&data[*off..*off + dest.len()]);
|
|
65 |
@@ -345,7 +373,6 @@ impl TestRng {
|
|
66 |
pub(crate) fn default_rng(algorithm: RngAlgorithm) -> Self {
|
|
67 |
#[cfg(feature = "std")]
|
|
68 |
{
|
|
69 |
- use rand::FromEntropy;
|
|
70 |
Self {
|
|
71 |
rng: match algorithm {
|
|
72 |
RngAlgorithm::XorShift => {
|