From f8f32159eedf47296ed11f80f9fdb312653ebb26 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Thu, 10 Sep 2020 04:07:43 -0700 Subject: [PATCH 1/4] Update getrandom to 0.2 Signed-off-by: Joe Richey --- CHANGELOG.md | 1 + rand_core/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f634f19e6d3..8a7e3556c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update. - Implement weighted sampling without replacement (#976, #1013) ### Changes +- `getrandom` updated to v0.2 - `ThreadRng` is no longer `Copy` to enable safe usage within thread-local destructors (see #968) - `gen_range(a, b)` was replaced with `gen_range(a..b)`, and `gen_range(a..=b)` is supported (#744, #1003). Note that `a` and `b` can no longer be references or SIMD types. diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 1f18edabc23..4b85940ff70 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -25,7 +25,7 @@ serde1 = ["serde"] # enables serde for BlockRng wrapper [dependencies] serde = { version = "1", features = ["derive"], optional = true } -getrandom = { version = "0.1", optional = true } +getrandom = { version = "0.2", optional = true } [package.metadata.docs.rs] # To build locally: From 677241af4caaf0160a2c28de402d82e39af2f192 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Tue, 15 Sep 2020 01:25:58 +0200 Subject: [PATCH 2/4] Make sure that the error codes are identical to `getrandom` --- rand_core/src/error.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rand_core/src/error.rs b/rand_core/src/error.rs index b11e170c02f..8ed45b061d3 100644 --- a/rand_core/src/error.rs +++ b/rand_core/src/error.rs @@ -28,10 +28,14 @@ pub struct Error { impl Error { /// Codes at or above this point can be used by users to define their own /// custom errors. + /// + /// This is identical to `getrandom::Error::CUSTOM_START`. pub const CUSTOM_START: u32 = (1 << 31) + (1 << 30); /// Codes below this point represent OS Errors (i.e. positive i32 values). /// Codes at or above this point, but below [`Error::CUSTOM_START`] are /// reserved for use by the `rand` and `getrandom` crates. + /// + /// This is identical to `getrandom::Error::INTERNAL_START`. pub const INTERNAL_START: u32 = 1 << 31; /// Construct from any type supporting `std::error::Error` @@ -208,3 +212,14 @@ impl fmt::Display for ErrorCode { #[cfg(feature = "std")] impl std::error::Error for ErrorCode {} + +#[cfg(test)] +mod test { + #[cfg(feature = "getrandom")] + #[test] + fn test_error_codes() { + // Make sure the values are the same as in `getrandom`. + assert_eq!(super::Error::CUSTOM_START, getrandom::Error::CUSTOM_START); + assert_eq!(super::Error::INTERNAL_START, getrandom::Error::INTERNAL_START); + } +} From a75aa13c6e11b5d6f49a6ca95635b9b7140e7a0c Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Mon, 14 Sep 2020 23:43:57 -0700 Subject: [PATCH 3/4] rand_core: Add links to Error cross-refs Signed-off-by: Joe Richey --- rand_core/src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rand_core/src/error.rs b/rand_core/src/error.rs index 8ed45b061d3..d2e467da84d 100644 --- a/rand_core/src/error.rs +++ b/rand_core/src/error.rs @@ -29,13 +29,13 @@ impl Error { /// Codes at or above this point can be used by users to define their own /// custom errors. /// - /// This is identical to `getrandom::Error::CUSTOM_START`. + /// This is identical to [`getrandom::Error::CUSTOM_START`](https://docs.rs/getrandom/latest/getrandom/struct.Error.html#associatedconstant.CUSTOM_START). pub const CUSTOM_START: u32 = (1 << 31) + (1 << 30); /// Codes below this point represent OS Errors (i.e. positive i32 values). /// Codes at or above this point, but below [`Error::CUSTOM_START`] are /// reserved for use by the `rand` and `getrandom` crates. /// - /// This is identical to `getrandom::Error::INTERNAL_START`. + /// This is identical to [`getrandom::Error::INTERNAL_START`](https://docs.rs/getrandom/latest/getrandom/struct.Error.html#associatedconstant.INTERNAL_START). pub const INTERNAL_START: u32 = 1 << 31; /// Construct from any type supporting `std::error::Error` From 41f2e994dabf1a6561e98b7f1be7afd8db402727 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 15 Sep 2020 03:41:38 -0700 Subject: [PATCH 4/4] Add PR number Signed-off-by: Joe Richey --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a7e3556c94..d2037f36e74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update. - Implement weighted sampling without replacement (#976, #1013) ### Changes -- `getrandom` updated to v0.2 +- `getrandom` updated to v0.2 (#1041) - `ThreadRng` is no longer `Copy` to enable safe usage within thread-local destructors (see #968) - `gen_range(a, b)` was replaced with `gen_range(a..b)`, and `gen_range(a..=b)` is supported (#744, #1003). Note that `a` and `b` can no longer be references or SIMD types.