Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rand_core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ pub trait CryptoBlockRng: BlockRngCore {}
#[cfg_attr(
feature = "serde",
serde(
bound = "for<'x> R: Serialize + Deserialize<'x> + Sized, for<'x> R::Results: Serialize + Deserialize<'x>"
bound = "for<'x> R: Serialize + Deserialize<'x>, for<'x> R::Results: Serialize + Deserialize<'x>"
)
)]
pub struct BlockRng<R: BlockRngCore + ?Sized> {
pub struct BlockRng<R: BlockRngCore> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed because of the following warning:

warning: `?Sized` bound is ignored because of a `Sized` requirement
note: ...because `Deserialize` has the bound `Sized`

AFAIK we can not use this trait with DSTs either way, since we store core by value, so the ?Sized bound is not needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust does permit the last field of a struct to be unsized, but I can't see it being useful.

In this case we can drop the + Sized bound three lines up.

Copy link
Member Author

@newpavlov newpavlov Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust does permit the last field of a struct to be unsized,

Huh, TIL. I guess it's not surprising I did not encounter it in practice since in its current form it's a virtually useless feature and even docs state that:

Yes, custom DSTs are a largely half-baked feature for now.

results: R::Results,
index: usize,
/// The *core* part of the RNG, implementing the `generate` function.
Expand Down
5 changes: 1 addition & 4 deletions rand_distr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ pub(crate) fn log_gamma<F: Float>(x: F) -> F {
/// * `pdf`: the probability density function
/// * `zero_case`: manual sampling from the tail when we chose the
/// bottom box (i.e. i == 0)

// the perf improvement (25-50%) is definitely worth the extra code
// size from force-inlining.
#[inline(always)]
#[inline(always)] // Forced inlining improves the perf by 25-50%
pub(crate) fn ziggurat<R: Rng + ?Sized, P, Z>(
rng: &mut R,
symmetric: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/distr/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub trait Distribution<T> {
}
}

impl<'a, T, D: Distribution<T> + ?Sized> Distribution<T> for &'a D {
impl<T, D: Distribution<T> + ?Sized> Distribution<T> for &D {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy is pedantically complaining that we're being too pedantic?

(Sorry, I'll drop the sarcasm! This is fine.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, to be fair, it's a good lint for raising awareness that such elision is allowed. As an "old-timer" who was using Rust since before 1.31, I automatically was using the "pedantic" style everywhere.

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> T {
(*self).sample(rng)
}
Expand Down
2 changes: 1 addition & 1 deletion src/distr/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl std::error::Error for EmptySlice {}
/// Note: the `String` is potentially left with excess capacity; optionally the
/// user may call `string.shrink_to_fit()` afterwards.
#[cfg(feature = "alloc")]
impl<'a> super::DistString for Slice<'a, char> {
impl super::DistString for Slice<'_, char> {
fn append_string<R: crate::Rng + ?Sized>(&self, rng: &mut R, string: &mut String, len: usize) {
// Get the max char length to minimize extra space.
// Limit this check to avoid searching for long slice.
Expand Down
2 changes: 1 addition & 1 deletion src/distr/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ where
self
}
}
impl<'a, Borrowed> SampleBorrow<Borrowed> for &'a Borrowed
impl<Borrowed> SampleBorrow<Borrowed> for &Borrowed
where
Borrowed: SampleUniform,
{
Expand Down
6 changes: 3 additions & 3 deletions src/distr/weighted_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub struct WeightedIndexIter<'a, X: SampleUniform + PartialOrd> {
index: usize,
}

impl<'a, X> Debug for WeightedIndexIter<'a, X>
impl<X> Debug for WeightedIndexIter<'_, X>
where
X: SampleUniform + PartialOrd + Debug,
X::Sampler: Debug,
Expand All @@ -269,7 +269,7 @@ where
}
}

impl<'a, X> Clone for WeightedIndexIter<'a, X>
impl<X> Clone for WeightedIndexIter<'_, X>
where
X: SampleUniform + PartialOrd,
{
Expand All @@ -281,7 +281,7 @@ where
}
}

impl<'a, X> Iterator for WeightedIndexIter<'a, X>
impl<X> Iterator for WeightedIndexIter<'_, X>
where
X: for<'b> core::ops::SubAssign<&'b X> + SampleUniform + PartialOrd + Clone,
{
Expand Down
4 changes: 2 additions & 2 deletions src/seq/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub enum IndexVecIter<'a> {
U64(slice::Iter<'a, u64>),
}

impl<'a> Iterator for IndexVecIter<'a> {
impl Iterator for IndexVecIter<'_> {
type Item = usize;

#[inline]
Expand All @@ -176,7 +176,7 @@ impl<'a> Iterator for IndexVecIter<'a> {
}
}

impl<'a> ExactSizeIterator for IndexVecIter<'a> {}
impl ExactSizeIterator for IndexVecIter<'_> {}

/// Return type of `IndexVec::into_iter`.
#[derive(Clone, Debug)]
Expand Down