Skip to content

Commit 5fce5ec

Browse files
authored
Remove Clone for StdRng, new bound for ReseedingRng (#1677)
2 parents 5d07c2d + 1422700 commit 5fce5ec

File tree

3 files changed

+2
-47
lines changed

3 files changed

+2
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1717
- Fix `OsError::raw_os_error` on UEFI targets by returning `Option<usize>` (#1665)
1818
- Replace fn `TryRngCore::read_adapter(..) -> RngReadAdapter` with simpler struct `RngReader` (#1669)
1919
- Remove fns `SeedableRng::from_os_rng`, `try_from_os_rng` (#1674)
20+
- Remove `Clone` support for `StdRng`, `ReseedingRng` (#1677)
2021

2122
### Additions
2223
- Add fns `IndexedRandom::choose_iter`, `choose_weighted_iter` (#1632)

src/rngs/reseeding.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
2121
/// `ReseedingRng` reseeds the underlying PRNG in the following cases:
2222
///
2323
/// - On a manual call to [`reseed()`].
24-
/// - After `clone()`, the clone will be reseeded on first use.
2524
/// - After the PRNG has generated a configurable number of random bytes.
2625
///
2726
/// # When should reseeding after a fixed number of generated bytes be used?
@@ -62,9 +61,6 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
6261
/// let mut reseeding_rng = ReseedingRng::<ChaCha20Core, _>::new(0, OsRng).unwrap();
6362
///
6463
/// println!("{}", reseeding_rng.random::<u64>());
65-
///
66-
/// let mut cloned_rng = reseeding_rng.clone();
67-
/// assert!(reseeding_rng.random::<u64>() != cloned_rng.random::<u64>());
6864
/// ```
6965
///
7066
/// [`BlockRngCore`]: rand_core::block::BlockRngCore
@@ -124,18 +120,6 @@ where
124120
}
125121
}
126122

127-
impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr>
128-
where
129-
R: BlockRngCore + SeedableRng + Clone,
130-
Rsdr: TryRngCore + Clone,
131-
{
132-
fn clone(&self) -> ReseedingRng<R, Rsdr> {
133-
// Recreating `BlockRng` seems easier than cloning it and resetting
134-
// the index.
135-
ReseedingRng(BlockRng::new(self.0.core.clone()))
136-
}
137-
}
138-
139123
impl<R, Rsdr> CryptoRng for ReseedingRng<R, Rsdr>
140124
where
141125
R: BlockRngCore<Item = u32> + SeedableRng + CryptoBlockRng,
@@ -228,21 +212,6 @@ where
228212
}
229213
}
230214

231-
impl<R, Rsdr> Clone for ReseedingCore<R, Rsdr>
232-
where
233-
R: BlockRngCore + SeedableRng + Clone,
234-
Rsdr: TryRngCore + Clone,
235-
{
236-
fn clone(&self) -> ReseedingCore<R, Rsdr> {
237-
ReseedingCore {
238-
inner: self.inner.clone(),
239-
reseeder: self.reseeder.clone(),
240-
threshold: self.threshold,
241-
bytes_until_reseed: 0, // reseed clone on first use
242-
}
243-
}
244-
}
245-
246215
impl<R, Rsdr> CryptoBlockRng for ReseedingCore<R, Rsdr>
247216
where
248217
R: BlockRngCore<Item = u32> + SeedableRng + CryptoBlockRng,
@@ -277,19 +246,4 @@ mod test {
277246
assert_eq!(buf, seq);
278247
}
279248
}
280-
281-
#[test]
282-
#[allow(clippy::redundant_clone)]
283-
fn test_clone_reseeding() {
284-
let zero = const_rng(0);
285-
let mut rng1 = ReseedingRng::<Core, _>::new(32 * 4, zero).unwrap();
286-
287-
let first: u32 = rng1.random();
288-
for _ in 0..10 {
289-
let _ = rng1.random::<u32>();
290-
}
291-
292-
let mut rng2 = rng1.clone();
293-
assert_eq!(first, rng2.random::<u32>());
294-
}
295249
}

src/rngs/std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use chacha20::ChaCha12Rng as Rng;
6666
/// [CSPRNG]: https://rust-random.github.io/book/guide-gen.html#cryptographically-secure-pseudo-random-number-generator
6767
/// [rand_chacha]: https://crates.io/crates/rand_chacha
6868
/// [rand issue]: https://github.com/rust-random/rand/issues/932
69-
#[derive(Clone, Debug, PartialEq, Eq)]
69+
#[derive(Debug, PartialEq, Eq)]
7070
pub struct StdRng(Rng);
7171

7272
impl RngCore for StdRng {

0 commit comments

Comments
 (0)