From 19169cbce9931eea5ccb4f2cbf174fc9d3e8759d Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 6 Dec 2022 19:01:10 +0000 Subject: [PATCH] Bump MSRV to 1.56 (Edition 2021) (#1269) * Bump MSRV to 1.56 (Edition 2021) * Apply Clippy suggestions * Bump edition and add rust-version field to Cargo.toml * CI AVR test: unpin nightly rust version * Disable AVR test * Bump crate version numbers for a breaking release --- .github/workflows/test.yml | 24 ++++++++++++------------ Cargo.toml | 11 ++++++----- README.md | 7 ++++--- rand_chacha/Cargo.toml | 7 ++++--- rand_chacha/README.md | 2 +- rand_core/Cargo.toml | 5 +++-- rand_core/README.md | 2 +- rand_core/src/block.rs | 4 ++-- rand_distr/Cargo.toml | 11 ++++++----- rand_distr/README.md | 2 +- rand_distr/benches/Cargo.toml | 5 +++-- rand_pcg/Cargo.toml | 7 ++++--- rand_pcg/README.md | 2 +- rustfmt.toml | 2 +- src/distributions/uniform.rs | 2 +- src/rngs/adapter/reseeding.rs | 4 ++-- src/seq/index.rs | 4 ++-- src/seq/mod.rs | 2 +- 18 files changed, 55 insertions(+), 48 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d64a5352b7..50dd5e8672b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,7 @@ jobs: # Test both windows-gnu and windows-msvc; use beta rust on one - os: ubuntu-latest target: x86_64-unknown-linux-gnu - toolchain: 1.51.0 # MSRV + toolchain: 1.56.0 # MSRV - os: ubuntu-latest deps: sudo apt-get update ; sudo apt install gcc-multilib target: i686-unknown-linux-gnu @@ -161,17 +161,17 @@ jobs: - name: Build top-level only run: cargo build --target=thumbv6m-none-eabi --no-default-features - test-avr: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Install toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly-2021-01-07 # Pinned compiler version due to https://github.com/rust-lang/compiler-builtins/issues/400 - components: rust-src - - name: Build top-level only - run: cargo build -Z build-std=core --target=avr-unknown-gnu-atmega328 --no-default-features + # Disabled due to lack of known working compiler versions (not older than our MSRV) + # test-avr: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Install toolchain + # uses: dtolnay/rust-toolchain@nightly + # with: + # components: rust-src + # - name: Build top-level only + # run: cargo build -Z build-std=core --target=avr-unknown-gnu-atmega328 --no-default-features test-ios: runs-on: macos-latest diff --git a/Cargo.toml b/Cargo.toml index bc39334db66..71b430f5467 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand" -version = "0.8.5" +version = "0.9.0" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -13,7 +13,8 @@ Random number generators and other randomness functionality. keywords = ["random", "rng"] categories = ["algorithms", "no-std"] autobenches = true -edition = "2018" +edition = "2021" +rust-version = "1.56" include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] [package.metadata.docs.rs] @@ -59,17 +60,17 @@ members = [ ] [dependencies] -rand_core = { path = "rand_core", version = "0.6.0" } +rand_core = { path = "rand_core", version = "0.7.0" } log = { version = "0.4.4", optional = true } serde = { version = "1.0.103", features = ["derive"], optional = true } -rand_chacha = { path = "rand_chacha", version = "0.3.0", default-features = false, optional = true } +rand_chacha = { path = "rand_chacha", version = "0.4.0", default-features = false, optional = true } [target.'cfg(unix)'.dependencies] # Used for fork protection (reseeding.rs) libc = { version = "0.2.22", optional = true, default-features = false } [dev-dependencies] -rand_pcg = { path = "rand_pcg", version = "0.3.0" } +rand_pcg = { path = "rand_pcg", version = "0.4.0" } # Only to test serde1 bincode = "1.2.1" rayon = "1.5.3" diff --git a/README.md b/README.md index 0952d8c6305..c4704f3dc44 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand) [![API](https://docs.rs/rand/badge.svg)](https://docs.rs/rand) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.51+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) A Rust library for random number generation, featuring: @@ -95,9 +95,10 @@ Some versions of Rand crates have been yanked ("unreleased"). Where this occurs, the crate's CHANGELOG *should* be updated with a rationale, and a search on the issue tracker with the keyword `yank` *should* uncover the motivation. -### Rust version requirements (MSRV) +### Rust version requirements -This version of Rand requires Rustc >= 1.51.0. +The Minimum Supported Rust Version (MSRV) is `rustc >= 1.56.0`. +Older releases may work (depending on feature configuration) but are untested. ## Crate Features diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index c4f5c113142..7584b788265 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_chacha" -version = "0.3.1" +version = "0.4.0" authors = ["The Rand Project Developers", "The Rust Project Developers", "The CryptoCorrosion Contributors"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -12,10 +12,11 @@ ChaCha random number generator """ keywords = ["random", "rng", "chacha"] categories = ["algorithms", "no-std"] -edition = "2018" +edition = "2021" +rust-version = "1.56" [dependencies] -rand_core = { path = "../rand_core", version = "0.6.0" } +rand_core = { path = "../rand_core", version = "0.7.0" } ppv-lite86 = { version = "0.2.14", default-features = false, features = ["simd"] } serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/rand_chacha/README.md b/rand_chacha/README.md index df52ab44ba8..851490e22aa 100644 --- a/rand_chacha/README.md +++ b/rand_chacha/README.md @@ -5,7 +5,7 @@ [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_chacha) [![API](https://docs.rs/rand_chacha/badge.svg)](https://docs.rs/rand_chacha) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.51+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) A cryptographically secure random number generator that uses the ChaCha algorithm. diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index bfaa029bada..a3640068e00 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_core" -version = "0.6.4" +version = "0.7.0" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -12,7 +12,8 @@ Core random number generator traits and tools for implementation. """ keywords = ["random", "rng"] categories = ["algorithms", "no-std"] -edition = "2018" +edition = "2021" +rust-version = "1.56" [package.metadata.docs.rs] # To build locally: diff --git a/rand_core/README.md b/rand_core/README.md index a7362d197df..4174ff19484 100644 --- a/rand_core/README.md +++ b/rand_core/README.md @@ -5,7 +5,7 @@ [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_core) [![API](https://docs.rs/rand_core/badge.svg)](https://docs.rs/rand_core) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.51+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) Core traits and error types of the [rand] library, plus tools for implementing RNGs. diff --git a/rand_core/src/block.rs b/rand_core/src/block.rs index a527dda2971..5a986895484 100644 --- a/rand_core/src/block.rs +++ b/rand_core/src/block.rs @@ -381,13 +381,13 @@ impl> RngCore for BlockRng64 { let mut read_len = 0; self.half_used = false; while read_len < dest.len() { - if self.index as usize >= self.results.as_ref().len() { + if self.index >= self.results.as_ref().len() { self.core.generate(&mut self.results); self.index = 0; } let (consumed_u64, filled_u8) = fill_via_u64_chunks( - &self.results.as_ref()[self.index as usize..], + &self.results.as_ref()[self.index..], &mut dest[read_len..], ); diff --git a/rand_distr/Cargo.toml b/rand_distr/Cargo.toml index 32a5fcaf5ae..ff1400d6e6e 100644 --- a/rand_distr/Cargo.toml +++ b/rand_distr/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_distr" -version = "0.4.3" +version = "0.5.0" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -12,7 +12,8 @@ Sampling from random number distributions """ keywords = ["random", "rng", "distribution", "probability"] categories = ["algorithms", "no-std"] -edition = "2018" +edition = "2021" +rust-version = "1.56" include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] [features] @@ -23,14 +24,14 @@ std_math = ["num-traits/std"] serde1 = ["serde", "rand/serde1"] [dependencies] -rand = { path = "..", version = "0.8.0", default-features = false } +rand = { path = "..", version = "0.9.0", default-features = false } num-traits = { version = "0.2", default-features = false, features = ["libm"] } serde = { version = "1.0.103", features = ["derive"], optional = true } [dev-dependencies] -rand_pcg = { version = "0.3.0", path = "../rand_pcg" } +rand_pcg = { version = "0.4.0", path = "../rand_pcg" } # For inline examples -rand = { path = "..", version = "0.8.0", default-features = false, features = ["std_rng", "std", "small_rng"] } +rand = { path = "..", version = "0.9.0", default-features = false, features = ["std_rng", "std", "small_rng"] } # Histogram implementation for testing uniformity average = { version = "0.13", features = [ "std" ] } # Special functions for testing distributions diff --git a/rand_distr/README.md b/rand_distr/README.md index 9096e918fd9..d11a3744c41 100644 --- a/rand_distr/README.md +++ b/rand_distr/README.md @@ -5,7 +5,7 @@ [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_distr) [![API](https://docs.rs/rand_distr/badge.svg)](https://docs.rs/rand_distr) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.51+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) Implements a full suite of random number distribution sampling routines. diff --git a/rand_distr/benches/Cargo.toml b/rand_distr/benches/Cargo.toml index 093286d57df..aeba667b3b4 100644 --- a/rand_distr/benches/Cargo.toml +++ b/rand_distr/benches/Cargo.toml @@ -4,7 +4,8 @@ version = "0.0.0" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" description = "Criterion benchmarks of the rand_distr crate" -edition = "2018" +edition = "2021" +rust-version = "1.56" publish = false [workspace] @@ -19,4 +20,4 @@ rand_pcg = { path = "../../rand_pcg/" } [[bench]] name = "distributions" path = "src/distributions.rs" -harness = false \ No newline at end of file +harness = false diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index 8ef7a3b5052..80099769275 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_pcg" -version = "0.3.1" +version = "0.4.0" authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -12,13 +12,14 @@ Selected PCG random number generators """ keywords = ["random", "rng", "pcg"] categories = ["algorithms", "no-std"] -edition = "2018" +edition = "2021" +rust-version = "1.56" [features] serde1 = ["serde"] [dependencies] -rand_core = { path = "../rand_core", version = "0.6.0" } +rand_core = { path = "../rand_core", version = "0.7.0" } serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] diff --git a/rand_pcg/README.md b/rand_pcg/README.md index d2c9259f181..ce6d1f37c6c 100644 --- a/rand_pcg/README.md +++ b/rand_pcg/README.md @@ -5,7 +5,7 @@ [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/) [![API](https://img.shields.io/badge/api-master-yellow.svg)](https://rust-random.github.io/rand/rand_pcg) [![API](https://docs.rs/rand_pcg/badge.svg)](https://docs.rs/rand_pcg) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.51+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)](https://github.com/rust-random/rand#rust-version-requirements) Implements a selection of PCG random number generators. diff --git a/rustfmt.toml b/rustfmt.toml index 6a2d9d48215..ded1e7812fb 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -19,7 +19,7 @@ where_single_line = true # struct_field_align_threshold = 20 # Compatibility: -edition = "2018" # we require compatibility back to 1.32.0 +edition = "2021" # Misc: inline_attribute_width = 80 diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index a7b4cb1a777..49703b84e46 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -340,7 +340,7 @@ where Borrowed: SampleUniform { #[inline(always)] fn borrow(&self) -> &Borrowed { - *self + self } } diff --git a/src/rngs/adapter/reseeding.rs b/src/rngs/adapter/reseeding.rs index 5ab453c928e..b78b850a4a6 100644 --- a/src/rngs/adapter/reseeding.rs +++ b/src/rngs/adapter/reseeding.rs @@ -208,8 +208,8 @@ where ReseedingCore { inner: rng, reseeder, - threshold: threshold as i64, - bytes_until_reseed: threshold as i64, + threshold, + bytes_until_reseed: threshold, fork_counter: 0, } } diff --git a/src/seq/index.rs b/src/seq/index.rs index 7682facd51e..ecd7d9f7383 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -238,7 +238,7 @@ where R: Rng + ?Sized { if amount < 163 { const C: [[f32; 2]; 2] = [[1.6, 8.0 / 45.0], [10.0, 70.0 / 9.0]]; - let j = if length < 500_000 { 0 } else { 1 }; + let j = usize::from(length >= 500_000); let amount_fp = amount as f32; let m4 = C[0][j] * amount_fp; // Short-cut: when amount < 12, floyd's is always faster @@ -249,7 +249,7 @@ where R: Rng + ?Sized { } } else { const C: [f32; 2] = [270.0, 330.0 / 9.0]; - let j = if length < 500_000 { 0 } else { 1 }; + let j = usize::from(length >= 500_000); if (length as f32) < C[j] * (amount as f32) { sample_inplace(rng, length, amount) } else { diff --git a/src/seq/mod.rs b/src/seq/mod.rs index 420ef253d5e..24c65bc9f08 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -641,7 +641,7 @@ impl<'a, S: Index + ?Sized + 'a, T: 'a> Iterator for SliceCho fn next(&mut self) -> Option { // TODO: investigate using SliceIndex::get_unchecked when stable - self.indices.next().map(|i| &self.slice[i as usize]) + self.indices.next().map(|i| &self.slice[i]) } fn size_hint(&self) -> (usize, Option) {