diff options
| author | Thom Chiovoloni <thom@shift.click> | 2022-11-20 16:55:41 -0800 |
|---|---|---|
| committer | Thom Chiovoloni <thom@shift.click> | 2023-01-04 14:52:41 -0800 |
| commit | a4bf36e87bdec61240fb3040774d008c70acbfbb (patch) | |
| tree | 0d742d0fae99a7f6ce94d6d0f12f4086fe5ae890 /library/alloc/src/lib.rs | |
| parent | 659e169d37990b9c730a59a96081f2ef7afbe8f1 (diff) | |
| download | rust-a4bf36e87bdec61240fb3040774d008c70acbfbb.tar.gz rust-a4bf36e87bdec61240fb3040774d008c70acbfbb.zip | |
Update rand in the stdlib tests, and remove the getrandom feature from it
Diffstat (limited to 'library/alloc/src/lib.rs')
| -rw-r--r-- | library/alloc/src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index bb1a85eb220..4e812529c2c 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -192,6 +192,7 @@ #![feature(unsized_fn_params)] #![feature(c_unwind)] #![feature(with_negative_coherence)] +#![cfg_attr(test, feature(panic_update_hook))] // // Rustdoc features: #![feature(doc_cfg)] @@ -255,3 +256,20 @@ pub mod vec; pub mod __export { pub use core::format_args; } + +#[cfg(test)] +#[allow(dead_code)] // Not used in all configurations +pub(crate) mod test_helpers { + /// Copied from `std::test_helpers::test_rng`, since these tests rely on the + /// seed not being the same for every RNG invocation too. + pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng { + use std::hash::{BuildHasher, Hash, Hasher}; + let mut hasher = std::collections::hash_map::RandomState::new().build_hasher(); + std::panic::Location::caller().hash(&mut hasher); + let hc64 = hasher.finish(); + let seed_vec = + hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<crate::vec::Vec<u8>>(); + let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap(); + rand::SeedableRng::from_seed(seed) + } +} |
