Skip to content

Commit 1a12c4c

Browse files
committed
relax Sized requirements on rng
1 parent e93ada0 commit 1a12c4c

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this library adheres to Rust's notion of
1010
### Changed
1111
- MSRV is now 1.63.0.
1212
- Migrated to `rand_core 0.9`.
13+
- `ff::Field::random(rng: impl RngCore) -> Self` has been changed back to
14+
`Field::random<R: RngCore + ?Sized>(rng: &mut R) -> Self`, to enable passing a
15+
trait object as the RNG.
1316

1417
### Removed
1518
- `derive_bits` feature flag (use `bits` instead).

ff_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ fn prime_field_impl(
12671267
const ONE: Self = R;
12681268

12691269
/// Computes a uniformly random element using rejection sampling.
1270-
fn random(mut rng: impl ::ff::derive::rand_core::RngCore) -> Self {
1270+
fn random<R: ::ff::derive::rand_core::RngCore + ?Sized>(rng: &mut R) -> Self {
12711271
loop {
12721272
let mut tmp = {
12731273
let mut repr = [0u64; #limbs];

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub trait Field:
7575
const ONE: Self;
7676

7777
/// Returns an element chosen uniformly at random using a user-provided RNG.
78-
fn random(rng: impl RngCore) -> Self;
78+
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self;
7979

8080
/// Returns true iff this element is zero.
8181
fn is_zero(&self) -> Choice {

tests/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod full_limbs {
3232
fn random_masking_does_not_overflow() {
3333
use ff::Field;
3434

35-
let _ = F384p::random(rand::rng());
35+
let _ = F384p::random(&mut rand::rng());
3636
}
3737
}
3838

0 commit comments

Comments
 (0)