Skip to content

rand_core: relax requirements on the param for SeedableRng#1641

Merged
dhardy merged 1 commit intorust-random:masterfrom
baloo:baloo/rand_core/relax-seedable
Aug 12, 2025
Merged

rand_core: relax requirements on the param for SeedableRng#1641
dhardy merged 1 commit intorust-random:masterfrom
baloo:baloo/rand_core/relax-seedable

Conversation

@baloo
Copy link
Contributor

@baloo baloo commented May 31, 2025

  • Added a CHANGELOG.md entry

Summary

This relax the Sized requirements on SeedableRng

Motivation

Mostly for API consistency

Details

This is an API break, but this should mostly be transparent as the default implementation is provided.

@dhardy
Copy link
Member

dhardy commented Jun 1, 2025

Mostly for API consistency

Given the API-breaking nature I'm not sure this is sufficient motivation. In any case, I'd prefer not to merge breaking changes for now.

Given that R is passed by &mut, I don't think relaxing the Sized constraint has much advantage.

@dhardy dhardy added the B-API Breakage: API label Jun 1, 2025
@newpavlov
Copy link
Member

newpavlov commented Jun 1, 2025

Given the API-breaking nature I'm not sure this is sufficient motivation.

Is it really a breaking change? In my understanding, ?Sized relaxes the implicitly added bound. The existing code which uses the R: RngCore should continue to work with the new bound. For example, see this snippet. Replacing impl Trait with an explicit type parameter should also not be an issue (though doing it in reverse direction could be problematic).

The only scenario which may cause issues I could think of, if the method implementation relies on RNG to be sized, which is highly unlikely in practice considering that we pass it be reference.

@dhardy
Copy link
Member

dhardy commented Jun 1, 2025

Is it really a breaking change?

These are trait methods; the impl must match (though I agree that it seems rustc could be more permissive here).

It shouldn't affect many (if any) people however since normally those methods are not explicitly implemented.

@baloo
Copy link
Contributor Author

baloo commented Jun 2, 2025

Mostly for API consistency

Given the API-breaking nature I'm not sure this is sufficient motivation. In any case, I'd prefer not to merge breaking changes for now.

Given that R is passed by &mut, I don't think relaxing the Sized constraint has much advantage.

Yeah, I do agree the motivation is not very strong.

I'm more than happy to wait, or even let go. But I wanted to raise the point. You decide :)

Like I said in my original comment, this is an API break, but it only affects people who would implement the trait, and that shouldn't be many people.
I haven't found a single implementor on GitHub (using rand_core 0.9).

@dhardy dhardy merged commit 07a0208 into rust-random:master Aug 12, 2025
15 checks passed
@dhardy dhardy mentioned this pull request Sep 10, 2025
@dhardy dhardy mentioned this pull request Oct 16, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-API Breakage: API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants