Skip to content

Commit 8b92c88

Browse files
committed
Bump MSRV to 1.51.0: support const generics by default
1 parent af7d3a9 commit 8b92c88

File tree

6 files changed

+6
-77
lines changed

6 files changed

+6
-77
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
env:
2424
RUSTDOCFLAGS: --cfg doc_cfg
2525
# --all builds all crates, but with default features for other crates (okay in this case)
26-
run: cargo deadlinks --ignore-fragments -- --all --features nightly,serde1,getrandom,small_rng,min_const_gen
26+
run: cargo deadlinks --ignore-fragments -- --all --features nightly,serde1,getrandom,small_rng
2727

2828
test:
2929
runs-on: ${{ matrix.os }}
@@ -47,7 +47,7 @@ jobs:
4747
# Test both windows-gnu and windows-msvc; use beta rust on one
4848
- os: ubuntu-latest
4949
target: x86_64-unknown-linux-gnu
50-
toolchain: 1.38.0 # MSRV
50+
toolchain: 1.51.0 # MSRV
5151
- os: ubuntu-latest
5252
deps: sudo apt-get update ; sudo apt install gcc-multilib
5353
target: i686-unknown-linux-gnu
@@ -77,21 +77,15 @@ jobs:
7777
cargo test --target ${{ matrix.target }} --all-features
7878
cargo test --target ${{ matrix.target }} --benches --features=nightly
7979
cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --benches
80-
cargo test --target ${{ matrix.target }} --lib --tests --no-default-features --features min_const_gen
80+
cargo test --target ${{ matrix.target }} --lib --tests --no-default-features
8181
- name: Test rand
8282
run: |
8383
cargo test --target ${{ matrix.target }} --lib --tests --no-default-features
8484
cargo build --target ${{ matrix.target }} --no-default-features --features alloc,getrandom,small_rng
8585
cargo test --target ${{ matrix.target }} --lib --tests --no-default-features --features=alloc,getrandom,small_rng
8686
cargo test --target ${{ matrix.target }} --examples
87-
- name: Test rand (all stable features, non-MSRV)
88-
if: ${{ matrix.toolchain != '1.38.0' }}
89-
run: |
90-
cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng,min_const_gen
91-
- name: Test rand (all stable features, MSRV)
92-
if: ${{ matrix.toolchain == '1.38.0' }}
87+
- name: Test rand (all stable features)
9388
run: |
94-
# const generics are not stable on 1.38.0
9589
cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng
9690
- name: Test rand_core
9791
run: |

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ std_rng = ["rand_chacha"]
5050
# Option: enable SmallRng
5151
small_rng = []
5252

53-
# Option: for rustc ≥ 1.51, enable generating random arrays of any size
54-
# using min-const-generics
55-
min_const_gen = []
56-
5753
[workspace]
5854
members = [
5955
"rand_core",

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ Additionally, these features configure Rand:
128128
- `nightly` enables some optimizations requiring nightly Rust
129129
- `simd_support` (experimental) enables sampling of SIMD values
130130
(uniformly random SIMD integers and floats), requiring nightly Rust
131-
- `min_const_gen` enables generating random arrays of
132-
any size using min-const-generics, requiring Rust ≥ 1.51.
133131

134132
Note that nightly features are not stable and therefore not all library and
135133
compiler versions will be compatible. This is especially true of Rand's

src/distributions/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,9 @@ use crate::Rng;
156156
/// compound types where all component types are supported:
157157
///
158158
/// * Tuples (up to 12 elements): each element is generated sequentially.
159-
/// * Arrays (up to 32 elements): each element is generated sequentially;
159+
/// * Arrays: each element is generated sequentially;
160160
/// see also [`Rng::fill`] which supports arbitrary array length for integer
161161
/// and float types and tends to be faster for `u32` and smaller types.
162-
/// When using `rustc` ≥ 1.51, enable the `min_const_gen` feature to support
163-
/// arrays larger than 32 elements.
164162
/// Note that [`Rng::fill`] and `Standard`'s array support are *not* equivalent:
165163
/// the former is optimised for integer types (using fewer RNG calls for
166164
/// element types smaller than the RNG word size), while the latter supports

src/distributions/other.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::Rng;
2020

2121
#[cfg(feature = "serde1")]
2222
use serde::{Serialize, Deserialize};
23-
#[cfg(feature = "min_const_gen")]
2423
use core::mem::{self, MaybeUninit};
2524

2625

@@ -189,8 +188,6 @@ tuple_impl! {A, B, C, D, E, F, G, H, I, J}
189188
tuple_impl! {A, B, C, D, E, F, G, H, I, J, K}
190189
tuple_impl! {A, B, C, D, E, F, G, H, I, J, K, L}
191190

192-
#[cfg(feature = "min_const_gen")]
193-
#[cfg_attr(doc_cfg, doc(cfg(feature = "min_const_gen")))]
194191
impl<T, const N: usize> Distribution<[T; N]> for Standard
195192
where Standard: Distribution<T>
196193
{
@@ -206,30 +203,6 @@ where Standard: Distribution<T>
206203
}
207204
}
208205

209-
#[cfg(not(feature = "min_const_gen"))]
210-
macro_rules! array_impl {
211-
// recursive, given at least one type parameter:
212-
{$n:expr, $t:ident, $($ts:ident,)*} => {
213-
array_impl!{($n - 1), $($ts,)*}
214-
215-
impl<T> Distribution<[T; $n]> for Standard where Standard: Distribution<T> {
216-
#[inline]
217-
fn sample<R: Rng + ?Sized>(&self, _rng: &mut R) -> [T; $n] {
218-
[_rng.gen::<$t>(), $(_rng.gen::<$ts>()),*]
219-
}
220-
}
221-
};
222-
// empty case:
223-
{$n:expr,} => {
224-
impl<T> Distribution<[T; $n]> for Standard {
225-
fn sample<R: Rng + ?Sized>(&self, _rng: &mut R) -> [T; $n] { [] }
226-
}
227-
};
228-
}
229-
230-
#[cfg(not(feature = "min_const_gen"))]
231-
array_impl! {32, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,}
232-
233206
impl<T> Distribution<Option<T>> for Standard
234207
where Standard: Distribution<T>
235208
{

src/rng.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ pub trait Rng: RngCore {
6868
///
6969
/// # Arrays and tuples
7070
///
71-
/// The `rng.gen()` method is able to generate arrays (up to 32 elements)
71+
/// The `rng.gen()` method is able to generate arrays
7272
/// and tuples (up to 12 elements), so long as all element types can be
7373
/// generated.
74-
/// When using `rustc` ≥ 1.51, enable the `min_const_gen` feature to support
75-
/// arrays larger than 32 elements.
7674
///
7775
/// For arrays of integers, especially for those with small element types
7876
/// (< 64 bit), it will likely be faster to instead use [`Rng::fill`].
@@ -392,8 +390,6 @@ macro_rules! impl_fill {
392390
impl_fill!(u16, u32, u64, usize, u128,);
393391
impl_fill!(i8, i16, i32, i64, isize, i128,);
394392

395-
#[cfg_attr(doc_cfg, doc(cfg(feature = "min_const_gen")))]
396-
#[cfg(feature = "min_const_gen")]
397393
impl<T, const N: usize> Fill for [T; N]
398394
where [T]: Fill
399395
{
@@ -402,32 +398,6 @@ where [T]: Fill
402398
}
403399
}
404400

405-
#[cfg(not(feature = "min_const_gen"))]
406-
macro_rules! impl_fill_arrays {
407-
($n:expr,) => {};
408-
($n:expr, $N:ident) => {
409-
impl<T> Fill for [T; $n] where [T]: Fill {
410-
fn try_fill<R: Rng + ?Sized>(&mut self, rng: &mut R) -> Result<(), Error> {
411-
self[..].try_fill(rng)
412-
}
413-
}
414-
};
415-
($n:expr, $N:ident, $($NN:ident,)*) => {
416-
impl_fill_arrays!($n, $N);
417-
impl_fill_arrays!($n - 1, $($NN,)*);
418-
};
419-
(!div $n:expr,) => {};
420-
(!div $n:expr, $N:ident, $($NN:ident,)*) => {
421-
impl_fill_arrays!($n, $N);
422-
impl_fill_arrays!(!div $n / 2, $($NN,)*);
423-
};
424-
}
425-
#[cfg(not(feature = "min_const_gen"))]
426-
#[rustfmt::skip]
427-
impl_fill_arrays!(32, N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,);
428-
#[cfg(not(feature = "min_const_gen"))]
429-
impl_fill_arrays!(!div 4096, N,N,N,N,N,N,N,);
430-
431401
#[cfg(test)]
432402
mod test {
433403
use super::*;

0 commit comments

Comments
 (0)