Skip to content

Commit

Permalink
Remove unnececcary ?Sized bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Feb 19, 2025
1 parent 2480249 commit 3e1ad57
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,3 @@ harness = false
[[bench]]
name = "int"
harness = false

[patch.crates-io]
# https://github.com/rust-random/rand/pull/1593
rand_core = { git = "https://github.com/fjarri/rand.git", branch = "sized" }
2 changes: 1 addition & 1 deletion src/int/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::Uint;

impl<const LIMBS: usize> Random for Int<LIMBS> {
/// Generate a cryptographically secure random [`Int`].
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: RngCore>(rng: &mut R) -> Self {
Self(Uint::random(rng))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/modular/const_monty_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ where
MOD: ConstMontyParams<LIMBS>,
{
#[inline]
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: RngCore>(rng: &mut R) -> Self {
Self::new(&Uint::random_mod(rng, MOD::MODULUS.as_nz_ref()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/odd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl PartialOrd<Odd<BoxedUint>> for BoxedUint {
#[cfg(feature = "rand_core")]
impl<const LIMBS: usize> Random for Odd<Uint<LIMBS>> {
/// Generate a random `Odd<Uint<T>>`.
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: RngCore>(rng: &mut R) -> Self {
let mut ret = Uint::random(rng);
ret.limbs[0] |= Limb::ONE;
Odd(ret)
Expand Down
6 changes: 3 additions & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub trait Random: Sized {
/// Generate a random value.
///
/// If `rng` is a CSRNG, the generation is cryptographically secure as well.
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self;
fn random<R: RngCore>(rng: &mut R) -> Self;
}

/// Possible errors of the methods in [`RandomBits`] trait.
Expand Down Expand Up @@ -419,7 +419,7 @@ pub trait RandomMod: Sized + Zero {
/// example, it implements `CryptoRng`), then this is guaranteed not to
/// leak anything about the output value aside from it being less than
/// `modulus`.
fn random_mod<R: RngCore + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self;
fn random_mod<R: RngCore>(rng: &mut R, modulus: &NonZero<Self>) -> Self;

/// Generate a random number which is less than a given `modulus`.
///
Expand All @@ -430,7 +430,7 @@ pub trait RandomMod: Sized + Zero {
/// example, it implements `CryptoRng`), then this is guaranteed not to
/// leak anything about the output value aside from it being less than
/// `modulus`.
fn try_random_mod<R: TryRngCore + ?Sized>(
fn try_random_mod<R: TryRngCore>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error>;
Expand Down
4 changes: 2 additions & 2 deletions src/uint/boxed/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ impl RandomBits for BoxedUint {
}

impl RandomMod for BoxedUint {
fn random_mod<R: RngCore + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self {
fn random_mod<R: RngCore>(rng: &mut R, modulus: &NonZero<Self>) -> Self {
let mut n = BoxedUint::zero_with_precision(modulus.bits_precision());
let Ok(()) = random_mod_core(rng, &mut n, modulus, modulus.bits());
n
}

fn try_random_mod<R: TryRngCore + ?Sized>(
fn try_random_mod<R: TryRngCore>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/uint/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<const LIMBS: usize> RandomBits for Uint<LIMBS> {
}

impl<const LIMBS: usize> RandomMod for Uint<LIMBS> {
fn random_mod<R: RngCore + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self {
fn random_mod<R: RngCore>(rng: &mut R, modulus: &NonZero<Self>) -> Self {
let mut n = Self::ZERO;
let Ok(()) = random_mod_core(rng, &mut n, modulus, modulus.bits_vartime());
n
Expand Down
2 changes: 1 addition & 1 deletion src/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {

#[cfg(feature = "rand_core")]
impl<T: Random> Random for Wrapping<T> {
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: RngCore>(rng: &mut R) -> Self {
Wrapping(Random::random(rng))
}
}
Expand Down

0 comments on commit 3e1ad57

Please sign in to comment.