From 66135e81c29c98f15d918db9b5a427a4cb25fbde Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Nov 2022 10:02:11 +0100 Subject: [PATCH 1/2] bump rand dependency of std tests --- Cargo.lock | 2 +- library/std/Cargo.toml | 2 +- library/std/src/collections/hash/map/tests.rs | 4 ++-- library/std/tests/env.rs | 7 +++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87a4124e7db01..c180451f8aa54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4780,7 +4780,7 @@ dependencies = [ "panic_abort", "panic_unwind", "profiler_builtins", - "rand 0.7.3", + "rand 0.8.5", "rustc-demangle", "std_detect", "unwind", diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index c10bfde4ddf79..e727d3d57af9b 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -33,7 +33,7 @@ default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] [dev-dependencies] -rand = "0.7" +rand = "0.8" [target.'cfg(any(all(target_family = "wasm", not(target_os = "emscripten")), all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies] dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] } diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs index 65634f2063f36..d68eb31268bc7 100644 --- a/library/std/src/collections/hash/map/tests.rs +++ b/library/std/src/collections/hash/map/tests.rs @@ -714,12 +714,12 @@ fn test_entry_take_doesnt_corrupt() { // Populate the map with some items. for _ in 0..50 { - let x = rng.gen_range(-10, 10); + let x = rng.gen_range(-10..10); m.insert(x, ()); } for _ in 0..1000 { - let x = rng.gen_range(-10, 10); + let x = rng.gen_range(-10..10); match m.entry(x) { Vacant(_) => {} Occupied(e) => { diff --git a/library/std/tests/env.rs b/library/std/tests/env.rs index b095c2dde6285..c6667712c866e 100644 --- a/library/std/tests/env.rs +++ b/library/std/tests/env.rs @@ -1,12 +1,11 @@ use std::env::*; use std::ffi::{OsStr, OsString}; -use rand::distributions::Alphanumeric; -use rand::{thread_rng, Rng}; +use rand::distributions::{Alphanumeric, DistString}; +use rand::thread_rng; fn make_rand_name() -> OsString { - let rng = thread_rng(); - let n = format!("TEST{}", rng.sample_iter(&Alphanumeric).take(10).collect::()); + let n = format!("TEST{}", Alphanumeric.sample_string(&mut thread_rng(), 10)); let n = OsString::from(n); assert!(var_os(&n).is_none()); n From d371c6cf51c77e199ac391f3f47ff6080ea3e943 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Nov 2022 10:07:02 +0100 Subject: [PATCH 2/2] bump rand dependency of alloc and core tests --- Cargo.lock | 92 ++++++------------------- library/alloc/Cargo.toml | 4 +- library/alloc/benches/slice.rs | 4 +- library/alloc/tests/slice.rs | 7 +- library/core/Cargo.toml | 4 +- library/core/benches/num/int_log/mod.rs | 4 +- 6 files changed, 33 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c180451f8aa54..be03acb2ade27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98" dependencies = [ - "getrandom 0.2.0", + "getrandom", "once_cell", "version_check", ] @@ -50,7 +50,7 @@ version = "0.0.0" dependencies = [ "compiler_builtins", "core", - "rand 0.7.3", + "rand", "rand_xorshift", ] @@ -878,7 +878,7 @@ dependencies = [ name = "core" version = "0.0.0" dependencies = [ - "rand 0.7.3", + "rand", "rand_xorshift", ] @@ -1506,17 +1506,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.0" @@ -1826,7 +1815,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1955a75fa080c677d3972822ec4bad316169ab1cfc6c257a942c2265dbe5fe" dependencies = [ "bitmaps", - "rand_core 0.6.2", + "rand_core", "rand_xoshiro", "sized-chunks", "typenum", @@ -2319,14 +2308,14 @@ version = "0.1.0" dependencies = [ "colored", "env_logger 0.9.0", - "getrandom 0.2.0", + "getrandom", "lazy_static", "libc", "libffi", "libloading", "log", "measureme", - "rand 0.8.5", + "rand", "regex", "rustc-workspace-hack", "rustc_version", @@ -2692,7 +2681,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ "phf_shared", - "rand 0.8.5", + "rand", ] [[package]] @@ -2858,19 +2847,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - [[package]] name = "rand" version = "0.8.5" @@ -2878,18 +2854,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -2899,16 +2865,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -2917,25 +2874,16 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.0", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] name = "rand_xorshift" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core 0.5.1", + "rand_core", ] [[package]] @@ -2944,7 +2892,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" dependencies = [ - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -2986,7 +2934,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.2.0", + "getrandom", "redox_syscall", ] @@ -3190,7 +3138,7 @@ dependencies = [ "bstr 0.2.17", "clap 3.2.20", "libz-sys", - "rand 0.8.5", + "rand", "regex", "serde_json", "syn", @@ -3691,7 +3639,7 @@ dependencies = [ name = "rustc_incremental" version = "0.0.0" dependencies = [ - "rand 0.8.5", + "rand", "rustc_ast", "rustc_data_structures", "rustc_errors", @@ -4353,7 +4301,7 @@ dependencies = [ name = "rustc_ty_utils" version = "0.0.0" dependencies = [ - "rand 0.8.5", + "rand", "rand_xoshiro", "rustc_data_structures", "rustc_errors", @@ -4780,7 +4728,7 @@ dependencies = [ "panic_abort", "panic_unwind", "profiler_builtins", - "rand 0.8.5", + "rand", "rustc-demangle", "std_detect", "unwind", diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index 265020209eb12..86e12f323d838 100644 --- a/library/alloc/Cargo.toml +++ b/library/alloc/Cargo.toml @@ -13,8 +13,8 @@ core = { path = "../core" } compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] } [dev-dependencies] -rand = "0.7" -rand_xorshift = "0.2" +rand = "0.8" +rand_xorshift = "0.3" [[test]] name = "collectionstests" diff --git a/library/alloc/benches/slice.rs b/library/alloc/benches/slice.rs index bd6f38f2f1003..ed58649266341 100644 --- a/library/alloc/benches/slice.rs +++ b/library/alloc/benches/slice.rs @@ -1,6 +1,6 @@ use std::{mem, ptr}; -use rand::distributions::{Alphanumeric, Standard}; +use rand::distributions::{Alphanumeric, Standard, DistString}; use rand::Rng; use test::{black_box, Bencher}; @@ -218,7 +218,7 @@ fn gen_strings(len: usize) -> Vec { let mut v = vec![]; for _ in 0..len { let n = rng.gen::() % 20 + 1; - v.push((&mut rng).sample_iter(&Alphanumeric).take(n).collect()); + v.push(Alphanumeric.sample_string(&mut rng, n)); } v } diff --git a/library/alloc/tests/slice.rs b/library/alloc/tests/slice.rs index 21f894343be09..a7bdf08055cdc 100644 --- a/library/alloc/tests/slice.rs +++ b/library/alloc/tests/slice.rs @@ -396,8 +396,11 @@ fn test_sort() { for len in (2..25).chain(500..510) { for &modulus in &[5, 10, 100, 1000] { for _ in 0..10 { - let orig: Vec<_> = - rng.sample_iter::(&Standard).map(|x| x % modulus).take(len).collect(); + let orig: Vec<_> = (&mut rng) + .sample_iter::(&Standard) + .map(|x| x % modulus) + .take(len) + .collect(); // Sort in default order. let mut v = orig.clone(); diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index 2a7df9556cfe1..f636ac97daedc 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -24,8 +24,8 @@ path = "benches/lib.rs" test = true [dev-dependencies] -rand = "0.7" -rand_xorshift = "0.2" +rand = "0.8" +rand_xorshift = "0.3" [features] # Make panics and failed asserts immediately abort without formatting any message diff --git a/library/core/benches/num/int_log/mod.rs b/library/core/benches/num/int_log/mod.rs index 3c01e2998cd2f..bb61224b5baad 100644 --- a/library/core/benches/num/int_log/mod.rs +++ b/library/core/benches/num/int_log/mod.rs @@ -21,7 +21,7 @@ macro_rules! int_log_bench { /* Exponentially distributed random numbers from the whole range of the type. */ let numbers: Vec<$t> = (0..256) .map(|_| { - let x = rng.gen::<$t>() >> rng.gen_range(0, <$t>::BITS); + let x = rng.gen::<$t>() >> rng.gen_range(0..<$t>::BITS); if x != 0 { x } else { 1 } }) .collect(); @@ -38,7 +38,7 @@ macro_rules! int_log_bench { /* Exponentially distributed random numbers from the range 0..256. */ let numbers: Vec<$t> = (0..256) .map(|_| { - let x = (rng.gen::() >> rng.gen_range(0, u8::BITS)) as $t; + let x = (rng.gen::() >> rng.gen_range(0..u8::BITS)) as $t; if x != 0 { x } else { 1 } }) .collect();