Skip to content

Commit 2afe585

Browse files
committed
Auto merge of #104658 - thomcc:rand-update-and-usable-no_std, r=Mark-Simulacrum
Update `rand` in the stdlib tests, and remove the `getrandom` feature from it. The main goal is actually removing `getrandom`, so that eventually we can allow running the stdlib test suite on tier3 targets which don't have `getrandom` support. Currently those targets can only run the subset of stdlib tests that exist in uitests, and (generally speaking), we prefer not to test libstd functionality in uitests, which came up recently in #104095 and #104185. Additionally, the fact that we can't update `rand`/`getrandom` means we're stuck with the old set of tier3 targets, so can't test new ones. ~~Anyway, I haven't checked that this actually does allow use on tier3 targets (I think it does not, as some work is needed in stdlib submodules) but it moves us slightly closer to this, and seems to allow at least finally updating our `rand` dep, which definitely improves the status quo.~~ Checked and works now. For the most part, our tests and benchmarks are fine using hard-coded seeds. A couple tests seem to fail with this (stuff manipulating the environment expecting no collisions, for example), or become pointless (all inputs to a function become equivalent). In these cases I've done a (gross) dance (ab)using `RandomState` and `Location::caller()` for some extra "entropy". Trying to share that code seems *way* more painful than it's worth given that the duplication is a 7-line function, even if the lines are quite gross. (Keeping in mind that sharing it would require adding `rand` as a non-dev dep to std, and exposing a type from it publicly, all of which sounds truly awful, even if done behind a perma-unstable feature). See also some previous attempts: - #86963 (in particular #86963 (comment) which explains why this is non-trivial) - #89131 - #96626 (comment) (I tried in that PR at the same time, but settled for just removing the usage of `thread_rng()` from the benchmarks, since that was the main goal). - #104185 - Probably more. It's very tempting of a thing to "just update". r? `@Mark-Simulacrum`
2 parents e5d46a5 + a4bf36e commit 2afe585

File tree

22 files changed

+508
-480
lines changed

22 files changed

+508
-480
lines changed

Cargo.lock

+34-91
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ version = "0.7.4"
3030
source = "registry+https://github.com/rust-lang/crates.io-index"
3131
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
3232
dependencies = [
33-
"getrandom 0.2.8",
33+
"getrandom",
3434
"once_cell",
3535
"version_check",
3636
]
@@ -50,7 +50,7 @@ version = "0.0.0"
5050
dependencies = [
5151
"compiler_builtins",
5252
"core",
53-
"rand 0.7.3",
53+
"rand",
5454
"rand_xorshift",
5555
]
5656

@@ -951,7 +951,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
951951
name = "core"
952952
version = "0.0.0"
953953
dependencies = [
954-
"rand 0.7.3",
954+
"rand",
955955
"rand_xorshift",
956956
]
957957

@@ -1055,7 +1055,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
10551055
checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef"
10561056
dependencies = [
10571057
"generic-array",
1058-
"rand_core 0.6.4",
1058+
"rand_core",
10591059
"subtle",
10601060
"zeroize",
10611061
]
@@ -1314,7 +1314,7 @@ version = "2.0.4"
13141314
source = "registry+https://github.com/rust-lang/crates.io-index"
13151315
checksum = "6a3d382e8464107391c8706b4c14b087808ecb909f6c15c34114bc42e53a9e4c"
13161316
dependencies = [
1317-
"getrandom 0.2.8",
1317+
"getrandom",
13181318
]
13191319

13201320
[[package]]
@@ -1351,7 +1351,7 @@ dependencies = [
13511351
"hkdf",
13521352
"pem-rfc7468",
13531353
"pkcs8",
1354-
"rand_core 0.6.4",
1354+
"rand_core",
13551355
"sec1",
13561356
"subtle",
13571357
"zeroize",
@@ -1482,7 +1482,7 @@ version = "0.12.1"
14821482
source = "registry+https://github.com/rust-lang/crates.io-index"
14831483
checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160"
14841484
dependencies = [
1485-
"rand_core 0.6.4",
1485+
"rand_core",
14861486
"subtle",
14871487
]
14881488

@@ -1749,17 +1749,6 @@ dependencies = [
17491749
"unicode-width",
17501750
]
17511751

1752-
[[package]]
1753-
name = "getrandom"
1754-
version = "0.1.16"
1755-
source = "registry+https://github.com/rust-lang/crates.io-index"
1756-
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
1757-
dependencies = [
1758-
"cfg-if",
1759-
"libc",
1760-
"wasi 0.9.0+wasi-snapshot-preview1",
1761-
]
1762-
17631752
[[package]]
17641753
name = "getrandom"
17651754
version = "0.2.8"
@@ -1769,7 +1758,7 @@ dependencies = [
17691758
"cfg-if",
17701759
"js-sys",
17711760
"libc",
1772-
"wasi 0.11.0+wasi-snapshot-preview1",
1761+
"wasi",
17731762
"wasm-bindgen",
17741763
]
17751764

@@ -1840,7 +1829,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
18401829
checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7"
18411830
dependencies = [
18421831
"ff",
1843-
"rand_core 0.6.4",
1832+
"rand_core",
18441833
"subtle",
18451834
]
18461835

@@ -2115,7 +2104,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
21152104
checksum = "af1955a75fa080c677d3972822ec4bad316169ab1cfc6c257a942c2265dbe5fe"
21162105
dependencies = [
21172106
"bitmaps",
2118-
"rand_core 0.6.4",
2107+
"rand_core",
21192108
"rand_xoshiro",
21202109
"sized-chunks",
21212110
"typenum",
@@ -2660,14 +2649,14 @@ version = "0.1.0"
26602649
dependencies = [
26612650
"colored",
26622651
"env_logger 0.9.0",
2663-
"getrandom 0.2.8",
2652+
"getrandom",
26642653
"lazy_static",
26652654
"libc",
26662655
"libffi",
26672656
"libloading",
26682657
"log",
26692658
"measureme",
2670-
"rand 0.8.5",
2659+
"rand",
26712660
"regex",
26722661
"rustc-workspace-hack",
26732662
"rustc_version",
@@ -2970,10 +2959,10 @@ checksum = "ed20c4c21d893414f42e0cbfebe8a8036b5ae9b0264611fb6504e395eda6ceec"
29702959
dependencies = [
29712960
"ct-codecs",
29722961
"ed25519-compact",
2973-
"getrandom 0.2.8",
2962+
"getrandom",
29742963
"orion",
29752964
"p384",
2976-
"rand_core 0.6.4",
2965+
"rand_core",
29772966
"regex",
29782967
"serde",
29792968
"serde_json",
@@ -3093,7 +3082,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
30933082
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
30943083
dependencies = [
30953084
"phf_shared",
3096-
"rand 0.8.5",
3085+
"rand",
30973086
]
30983087

30993088
[[package]]
@@ -3298,38 +3287,15 @@ dependencies = [
32983287
"proc-macro2",
32993288
]
33003289

3301-
[[package]]
3302-
name = "rand"
3303-
version = "0.7.3"
3304-
source = "registry+https://github.com/rust-lang/crates.io-index"
3305-
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
3306-
dependencies = [
3307-
"getrandom 0.1.16",
3308-
"libc",
3309-
"rand_chacha 0.2.2",
3310-
"rand_core 0.5.1",
3311-
"rand_hc",
3312-
]
3313-
33143290
[[package]]
33153291
name = "rand"
33163292
version = "0.8.5"
33173293
source = "registry+https://github.com/rust-lang/crates.io-index"
33183294
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
33193295
dependencies = [
33203296
"libc",
3321-
"rand_chacha 0.3.0",
3322-
"rand_core 0.6.4",
3323-
]
3324-
3325-
[[package]]
3326-
name = "rand_chacha"
3327-
version = "0.2.2"
3328-
source = "registry+https://github.com/rust-lang/crates.io-index"
3329-
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
3330-
dependencies = [
3331-
"ppv-lite86",
3332-
"rand_core 0.5.1",
3297+
"rand_chacha",
3298+
"rand_core",
33333299
]
33343300

33353301
[[package]]
@@ -3339,16 +3305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
33393305
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
33403306
dependencies = [
33413307
"ppv-lite86",
3342-
"rand_core 0.6.4",
3343-
]
3344-
3345-
[[package]]
3346-
name = "rand_core"
3347-
version = "0.5.1"
3348-
source = "registry+https://github.com/rust-lang/crates.io-index"
3349-
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
3350-
dependencies = [
3351-
"getrandom 0.1.16",
3308+
"rand_core",
33523309
]
33533310

33543311
[[package]]
@@ -3357,25 +3314,16 @@ version = "0.6.4"
33573314
source = "registry+https://github.com/rust-lang/crates.io-index"
33583315
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
33593316
dependencies = [
3360-
"getrandom 0.2.8",
3361-
]
3362-
3363-
[[package]]
3364-
name = "rand_hc"
3365-
version = "0.2.0"
3366-
source = "registry+https://github.com/rust-lang/crates.io-index"
3367-
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
3368-
dependencies = [
3369-
"rand_core 0.5.1",
3317+
"getrandom",
33703318
]
33713319

33723320
[[package]]
33733321
name = "rand_xorshift"
3374-
version = "0.2.0"
3322+
version = "0.3.0"
33753323
source = "registry+https://github.com/rust-lang/crates.io-index"
3376-
checksum = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8"
3324+
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
33773325
dependencies = [
3378-
"rand_core 0.5.1",
3326+
"rand_core",
33793327
]
33803328

33813329
[[package]]
@@ -3384,7 +3332,7 @@ version = "0.6.0"
33843332
source = "registry+https://github.com/rust-lang/crates.io-index"
33853333
checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa"
33863334
dependencies = [
3387-
"rand_core 0.6.4",
3335+
"rand_core",
33883336
]
33893337

33903338
[[package]]
@@ -3426,7 +3374,7 @@ version = "0.4.0"
34263374
source = "registry+https://github.com/rust-lang/crates.io-index"
34273375
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
34283376
dependencies = [
3429-
"getrandom 0.2.8",
3377+
"getrandom",
34303378
"redox_syscall",
34313379
]
34323380

@@ -3640,10 +3588,10 @@ version = "1.0.0"
36403588
dependencies = [
36413589
"bstr 0.2.17",
36423590
"clap 3.2.20",
3643-
"getrandom 0.2.8",
3591+
"getrandom",
36443592
"libc",
36453593
"libz-sys",
3646-
"rand 0.8.5",
3594+
"rand",
36473595
"regex",
36483596
"serde_json",
36493597
"syn",
@@ -3656,7 +3604,7 @@ name = "rustc_abi"
36563604
version = "0.0.0"
36573605
dependencies = [
36583606
"bitflags",
3659-
"rand 0.8.5",
3607+
"rand",
36603608
"rand_xoshiro",
36613609
"rustc_data_structures",
36623610
"rustc_index",
@@ -4162,7 +4110,7 @@ dependencies = [
41624110
name = "rustc_incremental"
41634111
version = "0.0.0"
41644112
dependencies = [
4165-
"rand 0.8.5",
4113+
"rand",
41664114
"rustc_ast",
41674115
"rustc_data_structures",
41684116
"rustc_errors",
@@ -5185,7 +5133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
51855133
checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c"
51865134
dependencies = [
51875135
"digest",
5188-
"rand_core 0.6.4",
5136+
"rand_core",
51895137
]
51905138

51915139
[[package]]
@@ -5345,11 +5293,12 @@ dependencies = [
53455293
"panic_abort",
53465294
"panic_unwind",
53475295
"profiler_builtins",
5348-
"rand 0.7.3",
5296+
"rand",
5297+
"rand_xorshift",
53495298
"rustc-demangle",
53505299
"std_detect",
53515300
"unwind",
5352-
"wasi 0.11.0+wasi-snapshot-preview1",
5301+
"wasi",
53535302
]
53545303

53555304
[[package]]
@@ -5821,7 +5770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
58215770
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
58225771
dependencies = [
58235772
"cfg-if",
5824-
"rand 0.8.5",
5773+
"rand",
58255774
"static_assertions",
58265775
]
58275776

@@ -6104,7 +6053,7 @@ version = "0.8.2"
61046053
source = "registry+https://github.com/rust-lang/crates.io-index"
61056054
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
61066055
dependencies = [
6107-
"getrandom 0.2.8",
6056+
"getrandom",
61086057
]
61096058

61106059
[[package]]
@@ -6145,12 +6094,6 @@ dependencies = [
61456094
"winapi-util",
61466095
]
61476096

6148-
[[package]]
6149-
name = "wasi"
6150-
version = "0.9.0+wasi-snapshot-preview1"
6151-
source = "registry+https://github.com/rust-lang/crates.io-index"
6152-
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
6153-
61546097
[[package]]
61556098
name = "wasi"
61566099
version = "0.11.0+wasi-snapshot-preview1"

library/alloc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ core = { path = "../core" }
1313
compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] }
1414

1515
[dev-dependencies]
16-
rand = "0.7"
17-
rand_xorshift = "0.2"
16+
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
17+
rand_xorshift = "0.3.0"
1818

1919
[[test]]
2020
name = "collectionstests"

library/alloc/benches/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{mem, ptr};
22

3-
use rand::distributions::{Alphanumeric, Standard};
3+
use rand::distributions::{Alphanumeric, DistString, Standard};
44
use rand::Rng;
55
use test::{black_box, Bencher};
66

@@ -218,7 +218,7 @@ fn gen_strings(len: usize) -> Vec<String> {
218218
let mut v = vec![];
219219
for _ in 0..len {
220220
let n = rng.gen::<usize>() % 20 + 1;
221-
v.push((&mut rng).sample_iter(&Alphanumeric).take(n).collect());
221+
v.push(Alphanumeric.sample_string(&mut rng, n));
222222
}
223223
v
224224
}

library/alloc/src/collections/binary_heap/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn test_retain() {
465465
#[test]
466466
#[cfg(not(target_os = "emscripten"))]
467467
fn panic_safe() {
468-
use rand::{seq::SliceRandom, thread_rng};
468+
use rand::seq::SliceRandom;
469469
use std::cmp;
470470
use std::panic::{self, AssertUnwindSafe};
471471
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -490,7 +490,7 @@ fn panic_safe() {
490490
self.0.partial_cmp(&other.0)
491491
}
492492
}
493-
let mut rng = thread_rng();
493+
let mut rng = crate::test_helpers::test_rng();
494494
const DATASZ: usize = 32;
495495
// Miri is too slow
496496
let ntest = if cfg!(miri) { 1 } else { 10 };

0 commit comments

Comments
 (0)