Skip to content

Commit 6951164

Browse files
committed
Bump MSRV to 1.51.0: support const generics by default
1 parent db80c40 commit 6951164

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
@@ -162,11 +162,9 @@ use crate::Rng;
162162
/// compound types where all component types are supported:
163163
///
164164
/// * Tuples (up to 12 elements): each element is generated sequentially.
165-
/// * Arrays (up to 32 elements): each element is generated sequentially;
165+
/// * Arrays: each element is generated sequentially;
166166
/// see also [`Rng::fill`] which supports arbitrary array length for integer
167167
/// and float types and tends to be faster for `u32` and smaller types.
168-
/// When using `rustc` ≥ 1.51, enable the `min_const_gen` feature to support
169-
/// arrays larger than 32 elements.
170168
/// Note that [`Rng::fill`] and `Standard`'s array support are *not* equivalent:
171169
/// the former is optimised for integer types (using fewer RNG calls for
172170
/// 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
#[cfg(feature = "simd_support")]
2625
use core::simd::*;
@@ -236,8 +235,6 @@ tuple_impl! {A, B, C, D, E, F, G, H, I, J}
236235
tuple_impl! {A, B, C, D, E, F, G, H, I, J, K}
237236
tuple_impl! {A, B, C, D, E, F, G, H, I, J, K, L}
238237

239-
#[cfg(feature = "min_const_gen")]
240-
#[cfg_attr(doc_cfg, doc(cfg(feature = "min_const_gen")))]
241238
impl<T, const N: usize> Distribution<[T; N]> for Standard
242239
where Standard: Distribution<T>
243240
{
@@ -253,30 +250,6 @@ where Standard: Distribution<T>
253250
}
254251
}
255252

256-
#[cfg(not(feature = "min_const_gen"))]
257-
macro_rules! array_impl {
258-
// recursive, given at least one type parameter:
259-
{$n:expr, $t:ident, $($ts:ident,)*} => {
260-
array_impl!{($n - 1), $($ts,)*}
261-
262-
impl<T> Distribution<[T; $n]> for Standard where Standard: Distribution<T> {
263-
#[inline]
264-
fn sample<R: Rng + ?Sized>(&self, _rng: &mut R) -> [T; $n] {
265-
[_rng.gen::<$t>(), $(_rng.gen::<$ts>()),*]
266-
}
267-
}
268-
};
269-
// empty case:
270-
{$n:expr,} => {
271-
impl<T> Distribution<[T; $n]> for Standard {
272-
fn sample<R: Rng + ?Sized>(&self, _rng: &mut R) -> [T; $n] { [] }
273-
}
274-
};
275-
}
276-
277-
#[cfg(not(feature = "min_const_gen"))]
278-
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,}
279-
280253
impl<T> Distribution<Option<T>> for Standard
281254
where Standard: Distribution<T>
282255
{

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)