Skip to content
/ rust Public
forked from rust-lang/rust

Commit

Permalink
Rollup merge of rust-lang#136983 - ehuss:misc-2024-prep, r=tgross35
Browse files Browse the repository at this point in the history
Prepare standard library for Rust 2024 migration

This includes a variety of commits preparing the standard library for migration to Rust 2024.

The actual migration is blocked on a few things, so I wanted to get this out of the way in a relatively digestable PR.
  • Loading branch information
jhpratt authored Feb 14, 2025
2 parents 8356c09 + ef20a1b commit b963ba2
Show file tree
Hide file tree
Showing 47 changed files with 256 additions and 157 deletions.
71 changes: 65 additions & 6 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ dependencies = [
"unwind",
]

[[package]]
name = "proc-macro2"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
dependencies = [
"unicode-ident",
]

[[package]]
name = "proc_macro"
version = "0.0.0"
Expand All @@ -230,6 +239,15 @@ dependencies = [
"cc",
]

[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]

[[package]]
name = "r-efi"
version = "4.5.0"
Expand All @@ -253,24 +271,28 @@ dependencies = [

[[package]]
name = "rand"
version = "0.8.5"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"rand_core",
"zerocopy",
]

[[package]]
name = "rand_core"
version = "0.6.4"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff"
dependencies = [
"zerocopy",
]

[[package]]
name = "rand_xorshift"
version = "0.3.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
dependencies = [
"rand_core",
]
Expand Down Expand Up @@ -352,6 +374,17 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "syn"
version = "2.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]

[[package]]
name = "sysroot"
version = "0.0.0"
Expand All @@ -372,6 +405,12 @@ dependencies = [
"std",
]

[[package]]
name = "unicode-ident"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"

[[package]]
name = "unicode-width"
version = "0.1.14"
Expand Down Expand Up @@ -492,3 +531,23 @@ name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

[[package]]
name = "zerocopy"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa91407dacce3a68c56de03abe2760159582b846c6a4acd2f456618087f12713"
dependencies = [
"zerocopy-derive",
]

[[package]]
name = "zerocopy-derive"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06718a168365cad3d5ff0bb133aad346959a2074bd4a85c121255a11304a8626"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
4 changes: 2 additions & 2 deletions library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ core = { path = "../core" }
compiler_builtins = { version = "=0.1.146", features = ['rustc-dep-of-std'] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
rand_xorshift = "0.3.0"
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }
rand_xorshift = "0.4.0"

[[test]]
name = "alloctests"
Expand Down
24 changes: 12 additions & 12 deletions library/alloc/benches/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ macro_rules! map_insert_rand_bench {
($name: ident, $n: expr, $map: ident) => {
#[bench]
pub fn $name(b: &mut Bencher) {
let n: usize = $n;
let n: u32 = $n;
let mut map = $map::new();
// setup
let mut rng = crate::bench_rng();

for _ in 0..n {
let i = rng.gen::<usize>() % n;
let i = rng.random::<u32>() % n;
map.insert(i, i);
}

// measure
b.iter(|| {
let k = rng.gen::<usize>() % n;
let k = rng.random::<u32>() % n;
map.insert(k, k);
map.remove(&k);
});
Expand Down Expand Up @@ -57,13 +57,13 @@ macro_rules! map_from_iter_rand_bench {
($name: ident, $n: expr, $map: ident) => {
#[bench]
pub fn $name(b: &mut Bencher) {
let n: usize = $n;
let n: u32 = $n;
// setup
let mut rng = crate::bench_rng();
let mut vec = Vec::with_capacity(n);
let mut vec = Vec::with_capacity(n as usize);

for _ in 0..n {
let i = rng.gen::<usize>() % n;
let i = rng.random::<u32>() % n;
vec.push((i, i));
}

Expand Down Expand Up @@ -102,11 +102,11 @@ macro_rules! map_find_rand_bench {
#[bench]
pub fn $name(b: &mut Bencher) {
let mut map = $map::new();
let n: usize = $n;
let n: u32 = $n;

// setup
let mut rng = crate::bench_rng();
let mut keys: Vec<_> = (0..n).map(|_| rng.gen::<usize>() % n).collect();
let mut keys: Vec<_> = (0..n).map(|_| rng.random::<u32>() % n).collect();

for &k in &keys {
map.insert(k, k);
Expand All @@ -115,9 +115,9 @@ macro_rules! map_find_rand_bench {
keys.shuffle(&mut rng);

// measure
let mut i = 0;
let mut i = 0u32;
b.iter(|| {
let t = map.get(&keys[i]);
let t = map.get(&keys[i as usize]);
i = (i + 1) % n;
black_box(t);
})
Expand Down Expand Up @@ -171,7 +171,7 @@ fn bench_iteration(b: &mut Bencher, size: i32) {
let mut rng = crate::bench_rng();

for _ in 0..size {
map.insert(rng.gen(), rng.gen());
map.insert(rng.random(), rng.random());
}

b.iter(|| {
Expand Down Expand Up @@ -201,7 +201,7 @@ fn bench_iteration_mut(b: &mut Bencher, size: i32) {
let mut rng = crate::bench_rng();

for _ in 0..size {
map.insert(rng.gen(), rng.gen());
map.insert(rng.random(), rng.random());
}

b.iter(|| {
Expand Down
8 changes: 4 additions & 4 deletions library/alloc/benches/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::collections::BTreeSet;
use rand::Rng;
use test::Bencher;

fn random(n: usize) -> BTreeSet<usize> {
fn random(n: u32) -> BTreeSet<u32> {
let mut rng = crate::bench_rng();
let mut set = BTreeSet::new();
while set.len() < n {
set.insert(rng.gen());
while set.len() < n as usize {
set.insert(rng.random());
}
assert_eq!(set.len(), n);
assert_eq!(set.len(), n as usize);
set
}

Expand Down
24 changes: 12 additions & 12 deletions library/alloc/benches/slice.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{mem, ptr};

use rand::Rng;
use rand::distributions::{Alphanumeric, DistString, Standard};
use rand::distr::{Alphanumeric, SampleString, StandardUniform};
use test::{Bencher, black_box};

#[bench]
Expand Down Expand Up @@ -156,7 +156,7 @@ fn random_inserts(b: &mut Bencher) {
let mut v = vec![(0, 0); 30];
for _ in 0..100 {
let l = v.len();
v.insert(rng.gen::<usize>() % (l + 1), (1, 1));
v.insert(rng.random::<u32>() as usize % (l + 1), (1, 1));
}
})
}
Expand All @@ -168,7 +168,7 @@ fn random_removes(b: &mut Bencher) {
let mut v = vec![(0, 0); 130];
for _ in 0..100 {
let l = v.len();
v.remove(rng.gen::<usize>() % l);
v.remove(rng.random::<u32>() as usize % l);
}
})
}
Expand All @@ -183,20 +183,20 @@ fn gen_descending(len: usize) -> Vec<u64> {

fn gen_random(len: usize) -> Vec<u64> {
let mut rng = crate::bench_rng();
(&mut rng).sample_iter(&Standard).take(len).collect()
(&mut rng).sample_iter(&StandardUniform).take(len).collect()
}

fn gen_random_bytes(len: usize) -> Vec<u8> {
let mut rng = crate::bench_rng();
(&mut rng).sample_iter(&Standard).take(len).collect()
(&mut rng).sample_iter(&StandardUniform).take(len).collect()
}

fn gen_mostly_ascending(len: usize) -> Vec<u64> {
let mut rng = crate::bench_rng();
let mut v = gen_ascending(len);
for _ in (0usize..).take_while(|x| x * x <= len) {
let x = rng.gen::<usize>() % len;
let y = rng.gen::<usize>() % len;
let x = rng.random::<u32>() as usize % len;
let y = rng.random::<u32>() as usize % len;
v.swap(x, y);
}
v
Expand All @@ -206,8 +206,8 @@ fn gen_mostly_descending(len: usize) -> Vec<u64> {
let mut rng = crate::bench_rng();
let mut v = gen_descending(len);
for _ in (0usize..).take_while(|x| x * x <= len) {
let x = rng.gen::<usize>() % len;
let y = rng.gen::<usize>() % len;
let x = rng.random::<u32>() as usize % len;
let y = rng.random::<u32>() as usize % len;
v.swap(x, y);
}
v
Expand All @@ -217,15 +217,15 @@ fn gen_strings(len: usize) -> Vec<String> {
let mut rng = crate::bench_rng();
let mut v = vec![];
for _ in 0..len {
let n = rng.gen::<usize>() % 20 + 1;
v.push(Alphanumeric.sample_string(&mut rng, n));
let n = rng.random::<u32>() % 20 + 1;
v.push(Alphanumeric.sample_string(&mut rng, n as usize));
}
v
}

fn gen_big_random(len: usize) -> Vec<[u64; 16]> {
let mut rng = crate::bench_rng();
(&mut rng).sample_iter(&Standard).map(|x| [x; 16]).take(len).collect()
(&mut rng).sample_iter(&StandardUniform).map(|x| [x; 16]).take(len).collect()
}

macro_rules! sort {
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! Creating a recursive data structure:
//!
//! ```
//! ##[allow(dead_code)]
//! # #[allow(dead_code)]
//! #[derive(Debug)]
//! enum List<T> {
//! Cons(T, Box<List<T>>),
Expand Down Expand Up @@ -97,12 +97,12 @@
//! #[repr(C)]
//! pub struct Foo;
//!
//! #[no_mangle]
//! #[unsafe(no_mangle)]
//! pub extern "C" fn foo_new() -> Box<Foo> {
//! Box::new(Foo)
//! }
//!
//! #[no_mangle]
//! #[unsafe(no_mangle)]
//! pub extern "C" fn foo_delete(_: Option<Box<Foo>>) {}
//! ```
//!
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// # // don't use this as a starting point for a real library.
/// # pub struct StreamWrapper { strm: *mut std::ffi::c_void }
/// # const Z_OK: i32 = 0;
/// # extern "C" {
/// # unsafe extern "C" {
/// # fn deflateGetDictionary(
/// # strm: *mut std::ffi::c_void,
/// # dictionary: *mut u8,
Expand Down
8 changes: 4 additions & 4 deletions library/alloc/tests/sort/patterns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;
use std::hash::Hash;
use std::str::FromStr;
use std::sync::OnceLock;

use rand::distr::Uniform;
use rand::prelude::*;
use rand_xorshift::XorShiftRng;

Expand All @@ -23,14 +23,14 @@ pub fn random(len: usize) -> Vec<i32> {

pub fn random_uniform<R>(len: usize, range: R) -> Vec<i32>
where
R: Into<rand::distributions::Uniform<i32>> + Hash,
Uniform<i32>: TryFrom<R, Error: std::fmt::Debug>,
{
// :.:.:.::

let mut rng: XorShiftRng = rand::SeedableRng::seed_from_u64(get_or_init_rand_seed());

// Abstracting over ranges in Rust :(
let dist: rand::distributions::Uniform<i32> = range.into();
let dist = Uniform::try_from(range).unwrap();
(0..len).map(|_| dist.sample(&mut rng)).collect()
}

Expand Down Expand Up @@ -207,5 +207,5 @@ fn rand_root_seed() -> u64 {

fn random_vec(len: usize) -> Vec<i32> {
let mut rng: XorShiftRng = rand::SeedableRng::seed_from_u64(get_or_init_rand_seed());
(0..len).map(|_| rng.gen::<i32>()).collect()
(0..len).map(|_| rng.random::<i32>()).collect()
}
Loading

0 comments on commit b963ba2

Please sign in to comment.