Skip to content

Commit 5005c99

Browse files
authored
Merge pull request #10459 from rust-lang/renovate/rand-0.x
Update Rust crate rand to v0.9.0
2 parents 65469f5 + af7d6ff commit 5005c99

File tree

8 files changed

+15
-23
lines changed

8 files changed

+15
-23
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ parking_lot = "=0.12.3"
102102
paste = "=1.0.15"
103103
postgres-native-tls = "=0.5.1"
104104
prometheus = { version = "=0.13.4", default-features = false }
105-
rand = "=0.8.5"
105+
rand = "=0.9.0"
106106
reqwest = { version = "=0.12.12", features = ["gzip", "json"] }
107107
rss = { version = "=2.0.11", default-features = false, features = ["atom"] }
108108
secrecy = "=0.10.3"

crates/crates_io_smoke_test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ anyhow = "=1.0.95"
1212
bytes = "=1.10.0"
1313
clap = { version = "=4.5.28", features = ["derive", "env", "unicode", "wrap_help"] }
1414
crates_io_index = { path = "../crates_io_index" }
15-
rand = "=0.8.5"
15+
rand = "=0.9.0"
1616
reqwest = { version = "=0.12.12", features = ["gzip", "json"] }
1717
secrecy = "=0.10.3"
1818
semver = { version = "=1.0.25", features = ["serde"] }

crates/crates_io_test_db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ crates_io_env_vars = { path = "../crates_io_env_vars" }
1212
diesel = { version = "=2.2.7", features = ["postgres", "r2d2"] }
1313
diesel-async = { version = "=0.5.2", features = ["postgres"] }
1414
diesel_migrations = { version = "=2.2.0", features = ["postgres"] }
15-
rand = "=0.8.5"
15+
rand = "=0.9.0"
1616
tracing = "=0.1.41"
1717
url = "=2.5.4"

crates/crates_io_test_db/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ fn run_migrations(conn: &mut PgConnection) -> diesel::migration::Result<()> {
216216
}
217217

218218
fn generate_name() -> String {
219-
let mut rng = rand::thread_rng();
219+
let mut rng = rand::rng();
220220
std::iter::repeat(())
221-
.map(|_| rng.sample(rand::distributions::Alphanumeric) as char)
221+
.map(|_| rng.sample(rand::distr::Alphanumeric) as char)
222222
.take(16)
223223
.collect()
224224
}

src/bin/crates-admin/populate.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use crates_io::{db, schema::version_downloads};
33
use diesel::prelude::*;
44
use diesel_async::scoped_futures::ScopedFutureExt;
55
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
6-
use rand::rngs::StdRng;
7-
use rand::{Rng, SeedableRng};
6+
use rand::Rng;
87

98
#[derive(clap::Parser, Debug)]
109
#[command(
@@ -27,11 +26,10 @@ async fn update(opts: Opts, conn: &mut AsyncPgConnection) -> QueryResult<()> {
2726
use diesel::dsl::*;
2827

2928
for id in opts.version_ids {
30-
let mut rng = StdRng::from_entropy();
31-
let mut dls = rng.gen_range(5_000i32..10_000);
29+
let mut dls = rand::rng().random_range(5_000i32..10_000);
3230

3331
for day in 0..90 {
34-
dls += rng.gen_range(-100..100);
32+
dls += rand::rng().random_range(-100..100);
3533

3634
diesel::insert_into(version_downloads::table)
3735
.values((

src/email.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use lettre::transport::smtp::authentication::{Credentials, Mechanism};
88
use lettre::transport::smtp::AsyncSmtpTransport;
99
use lettre::transport::stub::AsyncStubTransport;
1010
use lettre::{Address, AsyncTransport, Message, Tokio1Executor};
11-
use rand::distributions::{Alphanumeric, DistString};
11+
use rand::distr::{Alphanumeric, SampleString};
1212
use std::sync::Arc;
1313

1414
pub trait Email {
@@ -99,7 +99,7 @@ impl Emails {
9999
// replace it when it relays the message.
100100
let message_id = format!(
101101
"<{}@{}>",
102-
Alphanumeric.sample_string(&mut rand::thread_rng(), 32),
102+
Alphanumeric.sample_string(&mut rand::rng(), 32),
103103
self.domain,
104104
);
105105

src/util/token.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use diesel::{deserialize::FromSql, pg::Pg, serialize::ToSql, sql_types::Bytea};
2-
use rand::{distributions::Uniform, rngs::OsRng, Rng};
2+
use rand::distr::{Alphanumeric, SampleString};
33
use secrecy::{ExposeSecret, SecretSlice, SecretString};
44
use sha2::{Digest, Sha256};
55

@@ -84,13 +84,7 @@ impl ExposeSecret<str> for PlainToken {
8484
}
8585

8686
fn generate_secure_alphanumeric_string(len: usize) -> String {
87-
const CHARS: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
88-
89-
OsRng
90-
.sample_iter(Uniform::from(0..CHARS.len()))
91-
.map(|idx| CHARS[idx] as char)
92-
.take(len)
93-
.collect()
87+
Alphanumeric.sample_string(&mut rand::rng(), len)
9488
}
9589

9690
#[cfg(test)]

0 commit comments

Comments
 (0)