From 50bf18ab96c04b0312852d182f415228e77a2e4d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 9 Apr 2026 15:52:23 +0000 Subject: [PATCH 1/3] Deprecate feature log --- Cargo.lock | 1 - Cargo.toml | 5 ++--- README.md | 2 -- src/lib.rs | 3 --- src/log_macros.rs | 41 ----------------------------------------- src/rngs/thread.rs | 4 +--- 6 files changed, 3 insertions(+), 53 deletions(-) delete mode 100644 src/log_macros.rs diff --git a/Cargo.lock b/Cargo.lock index d3d6923f3f..f582b6bda5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,7 +239,6 @@ version = "0.10.0" dependencies = [ "chacha20", "getrandom", - "log", "postcard", "rand_core", "rand_pcg", diff --git a/Cargo.toml b/Cargo.toml index 30810babf6..c0363c6c8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,12 +58,11 @@ chacha = ["dep:chacha20"] # Note: enabling this option is expected to affect reproducibility of results. unbiased = [] -# Option: enable logging -log = ["dep:log"] +# Deprecated option: enable logging +log = [] [dependencies] rand_core = { version = "0.10.0", default-features = false } -log = { version = "0.4.4", optional = true } serde = { version = "1.0.103", features = ["derive"], optional = true } chacha20 = { version = "0.10.0", default-features = false, features = ["rng"], optional = true } getrandom = { version = "0.4.0", optional = true } diff --git a/README.md b/README.md index 0fb98fbb0c..2da1f6e520 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,6 @@ Rand is built with these features enabled by default: Optionally, the following dependencies can be enabled: - `chacha` enables `rand::rngs::{ChaCha8Rng, ChaCha12Rng, ChaCha20Rng}` (uses the [chacha20] crate) -- `log` enables logging (uses the [log] crate) Additionally, these features configure Rand: @@ -110,4 +109,3 @@ See [LICENSE-APACHE](https://github.com/rust-random/rand/blob/master/LICENSE-APA [getrandom]: https://crates.io/crates/getrandom [chacha20]: https://crates.io/crates/chacha20 -[log]: https://crates.io/crates/log diff --git a/src/lib.rs b/src/lib.rs index c7b85b94d6..51d26f5148 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,9 +71,6 @@ pub use rand_core; // Re-exports from rand_core pub use rand_core::{CryptoRng, Rng, SeedableRng, TryCryptoRng, TryRng}; -#[macro_use] -mod log_macros; - // Public modules pub mod distr; pub mod prelude; diff --git a/src/log_macros.rs b/src/log_macros.rs deleted file mode 100644 index fe0059c8f0..0000000000 --- a/src/log_macros.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow(unused)] - -macro_rules! trace { ($($x:tt)*) => ( - #[cfg(feature = "log")] - log::trace!($($x)*); - - #[cfg(not(feature = "log"))] - let _ = || { let _ = format_args!($($x)*); }; -) } - -macro_rules! debug { ($($x:tt)*) => ( - #[cfg(feature = "log")] - log::debug!($($x)*) - - #[cfg(not(feature = "log"))] - let _ = || { let _ = format_args!($($x)*); }; -) } - -macro_rules! info { ($($x:tt)*) => ( - #[cfg(feature = "log")] - log::info!($($x)*); - - #[cfg(not(feature = "log"))] - let _ = || { let _ = format_args!($($x)*); }; -) } - -macro_rules! warn { ($($x:tt)*) => ( - #[cfg(feature = "log")] - log::warn!($($x)*); - - #[cfg(not(feature = "log"))] - let _ = || { let _ = format_args!($($x)*); }; -) } - -macro_rules! error { ($($x:tt)*) => ( - #[cfg(feature = "log")] - log::error!($($x)*); - - #[cfg(not(feature = "log"))] - let _ = || { let _ = format_args!($($x)*); }; -) } diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index 9dd535c5ba..9ef8d06efe 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -66,10 +66,8 @@ impl ReseedingCore { #[cold] #[inline(never)] fn try_to_reseed(&mut self) { - trace!("Reseeding RNG (periodic reseed)"); - if let Err(e) = self.reseed() { - warn!("Reseeding RNG failed: {e}"); + panic!("Reseeding RNG failed: {e}"); } } } From 15b0fba5b3a80ac62d492a0bbf161085261f8313 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 9 Apr 2026 16:05:22 +0000 Subject: [PATCH 2/3] Document possible ThreadRng panics --- src/rngs/thread.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index 9ef8d06efe..1856ba2e13 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -67,7 +67,7 @@ impl ReseedingCore { #[inline(never)] fn try_to_reseed(&mut self) { if let Err(e) = self.reseed() { - panic!("Reseeding RNG failed: {e}"); + panic!("could not reseed ThreadRng: {e}"); } } } @@ -103,7 +103,7 @@ impl ReseedingCore { /// We leave it to the user to determine whether this generator meets their /// security requirements. For an alternative, see [`SysRng`]. /// -/// # Fork +/// # Forks and interrupts /// /// `ThreadRng` is not automatically reseeded on fork. It is recommended to /// explicitly call [`ThreadRng::reseed`] immediately after a fork, for example: @@ -121,7 +121,13 @@ impl ReseedingCore { /// from an interrupt (e.g. a fork handler) unless it can be guaranteed that no /// other method on the same `ThreadRng` is currently executing. /// +/// # Panics +/// +/// Implementations of [`TryRng`] and [`Rng`] panic in case of [`SysRng`] +/// failure during reseeding (highly unlikely). +/// /// [`StdRng`]: crate::rngs::StdRng +/// [`Rng`]: rand_core::Rng #[derive(Clone)] pub struct ThreadRng { // Rc is explicitly !Send and !Sync @@ -188,6 +194,10 @@ thread_local!( /// # Security /// /// Refer to [`ThreadRng#Security`]. +/// +/// # Panics +/// +/// This method panics in case of [`SysRng`] failure during initial seeding. pub fn rng() -> ThreadRng { let rng = THREAD_RNG_KEY.with(|t| t.clone()); ThreadRng { rng } From 605731b59aabb38338e65f2a6a7ba8a9e480d00d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Thu, 9 Apr 2026 15:54:20 +0000 Subject: [PATCH 3/3] Prepare rand v0.10.1 --- CHANGELOG.md | 12 ++++++++++-- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e220fcdea..d2f78fa65b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,15 @@ A [separate changelog is kept for rand_core](https://github.com/rust-random/core You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful. -## [Unreleased] -- Document panic behavior of `make_rng` and add `#[track_caller]` (#1761) +## [0.10.1] — 2026-02-11 +This release includes a fix for a soundness bug; see [#1763]. + +### Changes +- Document panic behavior of `make_rng` and add `#[track_caller]` ([#1761]) +- Deprecate feature `log` ([#1763]) + +[#1761]: https://github.com/rust-random/rand/pull/1761 +[#1763]: https://github.com/rust-random/rand/pull/1763 ## [0.10.0] - 2026-02-08 @@ -1150,6 +1157,7 @@ Code replaced with a compatibility layer over rand 0.4. - Separate `rand` out of the standard library [Unreleased]: https://github.com/rust-random/rand/compare/0.10.0...HEAD +[0.10.1]: https://github.com/rust-random/rand/compare/0.10.0...0.10.1 [0.10.0]: https://github.com/rust-random/rand/compare/0.9.2...0.10.0 [0.9.2]: https://github.com/rust-random/rand/compare/0.9.1...0.9.2 [0.9.1]: https://github.com/rust-random/rand/compare/0.9.0...0.9.1 diff --git a/Cargo.lock b/Cargo.lock index f582b6bda5..07f7de82f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,7 +235,7 @@ checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" [[package]] name = "rand" -version = "0.10.0" +version = "0.10.1" dependencies = [ "chacha20", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index c0363c6c8c..9bbef85456 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand" -version = "0.10.0" +version = "0.10.1" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md"