Skip to content

0.8.6#1772

Merged
dhardy merged 17 commits intorust-random:0.8from
nwalfield:0.8.6
Apr 16, 2026
Merged

0.8.6#1772
dhardy merged 17 commits intorust-random:0.8from
nwalfield:0.8.6

Conversation

@nwalfield
Copy link
Copy Markdown

Summary

This PR backports #1764 to version 0.8.5 of rand.

Motivation

There are still many packages that use rand 0.8. Leaf crates that depend on such packages are unable to address RUSTSEC-2026-0097 until their dependencies upgrade to a newer version of rand, which is likely to take a long time, or the fix is backported to 0.8. This PR does the latter.

Details

A request for a backport to 0.8 was raised in #1770 .

I work on Sequoia PGP. In Sequoia, we are currently stuck on an old version of Hickory as the latest version of Hickory dropped support for OpenSSL. We are currently looking for a solution to Hickory, but until then we have to live with Hickory and its dependencies, which include a dependency on rand 0.8.

@nwalfield nwalfield mentioned this pull request Apr 14, 2026
@nwalfield
Copy link
Copy Markdown
Author

@dhardy How do you prefer to handle these failures:

failures:

---- rand_core\src\lib.rs - SeedableRng::Seed (line 265) stdout ----
error: constant `N` is never used
   --> rand_core\src\lib.rs:269:7
    |
269 | const N: usize = 64;
    |       ^
    |
note: the lint level is defined here
   --> rand_core\src\lib.rs:263:9
    |
263 | #![deny(warnings)]
    |         ^^^^^^^^
    = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`

error: struct `MyRngSeed` is never constructed
   --> rand_core\src\lib.rs:270:12
    |
270 | pub struct MyRngSeed(pub [u8; N]);
    |            ^^^^^^^^^

error: struct `MyRng` is never constructed
   --> rand_core\src\lib.rs:271:12
    |
271 | pub struct MyRng(MyRngSeed);
    |            ^^^^^

error: aborting due to 3 previous errors

Couldn't compile the test.

failures:
    rand_core\src\lib.rs - SeedableRng::Seed (line 265)

test result: FAILED. 4 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.35s

error: doctest failed, to rerun pass `--doc`
Error: Process completed with exit code 1.

Should I disable deny(warnings), enable allow(dead_code) or remove the dead code?

Comment thread Cargo.toml
Comment thread src/lib.rs
Comment thread Cargo.toml Outdated
Comment thread CHANGELOG.md Outdated
@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 14, 2026

error: struct MyRng is never constructed

I think this could simply be solved by extending the example to use MyRng:

# let _rng = MyRng::from_seed(Default::default());

@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 14, 2026

Running RUSTDOCFLAGS="--cfg docsrs -Zunstable-options --generate-link-to-definition" cargo +nightly doc --all --all-features --no-deps (as now in Cargo.toml) fails; most errors are from the simd_support feature. So either remove that or switch to RUSTDOCFLAGS="--cfg docsrs -Zunstable-options --generate-link-to-definition" cargo +nightly doc --all --features serde1,getrandom,small_rng,min_const_gen --no-deps.

The latter still fails; looks like rand_core's lib.rs needs #![cfg_attr(docsrs, feature(doc_cfg))].

@nwalfield
Copy link
Copy Markdown
Author

error: struct MyRng is never constructed

I think this could simply be solved by extending the example to use MyRng:

# let _rng = MyRng::from_seed(Default::default());

That wasn't quite enough (rust complains about .0 not being used), but I've implemented this idea. Thanks.

@nwalfield
Copy link
Copy Markdown
Author

@dhardy The only test that fails is the 1.36 test. That fails because it is pulling in dependencies that 1.36 doesn't support:

 Downloading crates ...
  Downloaded getrandom v0.2.17
  Downloaded cfg-if v1.0.4
  Downloaded libc v0.2.185
error: failed to parse manifest at `/home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.185/Cargo.toml`

Caused by:
  failed to parse the `edition` key

Caused by:
  supported edition values are `2015` or `2018`, but `2021` is unknown
Error: Process completed with exit code 101.

Do you have any suggestions on how to handle this?

@nwalfield nwalfield requested a review from dhardy April 15, 2026 11:26
@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 15, 2026

@nwalfield this is probably fixable using "cargo update --precise" (and a lot of patience) to find compatible versions of each dependency.

If necessary we can raise the MSRV (or minimum tested version), but please try the above first.

Edit: sorry, it's not quite that simple. The proper solution would be to copy what we do in v0.9: once you have found a suitable Cargo.lock file, copy it to Cargo.lock.msrv then add a step like this to the CI test spec (including variant: MSRV in the matrix).

@nwalfield nwalfield force-pushed the 0.8.6 branch 2 times, most recently from aafa4c5 to e0b76b3 Compare April 15, 2026 19:46
Comment thread CHANGELOG.md
Comment thread .github/workflows/test.yml Outdated
@nwalfield nwalfield marked this pull request as ready for review April 16, 2026 11:05
dhardy and others added 7 commits April 16, 2026 13:08
Fix the following error:

```
warning: unexpected `cfg` condition name: `doc_cfg`
  --> rand_core/src/lib.rs:38:13
   |
38 | #![cfg_attr(doc_cfg, feature(doc_cfg))]
   |             ^^^^^^^
```

`doc_cfg` was used just to conditionally include the `doc_cfg` feature
in docs.rs builds.  That has since been standardized and changed to
`docsrs`.

Replace `doc_cfg` with `docsrs`.

See https://docs.rs/about/builds#detecting-docsrs .
Use `#[cfg(not(feature = "std"))]` to check for `std`, not
`#[cfg(not(std))]`.
Enable the `trusted_len` feature.

Implementing `TrustLen` is now unsafe.  Fix the implementation.
`rustc` complains that `error: struct MyRng is never constructed`.
Construct it, and use it.
Implementations of `FloatAsSIMD` and `BoolAsSIMD` are only used if the
`simd_support` feature is enabled.  Instead of making their definition
and several users conditional on `simd_support`, just suppress the
unused warning.
Modern versions of `rustc` warn about some elided lifetimes:

```
warning: hiding a lifetime that's elided elsewhere is confusing
   --> src/seq/mod.rs:115:27
    |
115 |     fn choose_multiple<R>(&self, rng: &mut R, amount: usize) -> SliceChooseIter<Self, Self::Item>
    |                           ^^^^^ the lifetime is elided here     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here
    |
    = help: the same lifetime is referred to in inconsistent ways, making the signature confusing
    = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: use `'_` for type paths
    |
115 |     fn choose_multiple<R>(&self, rng: &mut R, amount: usize) -> SliceChooseIter<'_, Self, Self::Item>
    |                                                                                 +++
```

Address the warnings.
Modern `rustc` doesn't know about the `asmjs` target.  Drop it.
v1 of `actions/cache` has been deprecated.
`simd_support` is an experimental feature, which does not work any
more.  Drop it.
The cross build test checks that `Rand` can be cross built for mips.
The Rust project no longer provides binaries for that target.  Switch
to arm, as on the `master` branch.
The latest versions of `ppv-lite86` and `libc` don't compile with
`rustc` 1.36.  When testing with `rustc` 1.36, use the last compatible
version of the dependencies.
@nwalfield
Copy link
Copy Markdown
Author

@nwalfield this is probably fixable using "cargo update --precise" (and a lot of patience) to find compatible versions of each dependency.

If necessary we can raise the MSRV (or minimum tested version), but please try the above first.

Edit: sorry, it's not quite that simple. The proper solution would be to copy what we do in v0.9: once you have found a suitable Cargo.lock file, copy it to Cargo.lock.msrv then add a step like this to the CI test spec (including variant: MSRV in the matrix).

FWIW, it took 6 hours of patience :D

@nwalfield
Copy link
Copy Markdown
Author

@dhardy CI now passes, and I think I've addressed all of the comments. Please let me know if there is something else that I should do.

Thanks!

Copy link
Copy Markdown
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

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

That's more patience than I had expected. Thanks for the effort.

The release date is wrong, but I guess it doesn't really matter.

@dhardy dhardy merged commit 5309f25 into rust-random:0.8 Apr 16, 2026
13 checks passed
@dhardy
Copy link
Copy Markdown
Member

dhardy commented Apr 17, 2026

Published

@nwalfield
Copy link
Copy Markdown
Author

@dhardy, thanks specifically for reviewing this, and publishing a new version, but also for your work on Rand. I appreciate it.

archlinux-github pushed a commit to archlinux/signstar that referenced this pull request Apr 17, 2026
This makes sure that the vulnerable `log` feature is unavailable.
And as such the advisory suppression is removed.

See: rust-random/rand#1772
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants