Skip to content

Commit b736407

Browse files
authored
Merge pull request #1246 from rust-random/work6
Bump MSRV to 1.51.0
2 parents 2569e9d + fbf06ff commit b736407

File tree

7 files changed

+31
-136
lines changed

7 files changed

+31
-136
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.36.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.36.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.36.0' }}
87+
- name: Test rand (all stable features)
9388
run: |
94-
# const generics are not stable on 1.36.0
9589
cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng
9690
- name: Test rand_core
9791
run: |

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ features = ["small_rng", "serde1"]
2828
[features]
2929
# Meta-features:
3030
default = ["std", "std_rng"]
31-
nightly = [] # enables performance optimizations requiring nightly rust
31+
nightly = [] # some additions requiring nightly Rust
3232
serde1 = ["serde", "rand_core/serde1"]
3333

3434
# Option (enabled by default): without "std" rand uses libcore; this option
@@ -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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ Optionally, the following dependencies can be enabled:
125125
Additionally, these features configure Rand:
126126

127127
- `small_rng` enables inclusion of the `SmallRng` PRNG
128-
- `nightly` enables some optimizations requiring nightly Rust
128+
- `nightly` includes some additions 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::*;

src/seq/index.rs

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ where R: Rng + ?Sized {
267267
/// sometimes be useful to have the indices themselves so this is provided as
268268
/// an alternative.
269269
///
270-
/// This implementation uses `O(length + amount)` space and `O(length)` time
271-
/// if the "nightly" feature is enabled, or `O(length)` space and
272-
/// `O(length + amount * log length)` time otherwise.
270+
/// This implementation uses `O(length + amount)` space and `O(length)` time.
273271
///
274272
/// Panics if `amount > length`.
275273
#[cfg(feature = "std")]
@@ -300,9 +298,7 @@ where
300298
///
301299
/// This implementation uses the algorithm described by Efraimidis and Spirakis
302300
/// in this paper: https://doi.org/10.1016/j.ipl.2005.11.003
303-
/// It uses `O(length + amount)` space and `O(length)` time if the
304-
/// "nightly" feature is enabled, or `O(length)` space and `O(length
305-
/// + amount * log length)` time otherwise.
301+
/// It uses `O(length + amount)` space and `O(length)` time.
306302
///
307303
/// Panics if `amount > length`.
308304
#[cfg(feature = "std")]
@@ -347,63 +343,33 @@ where
347343
}
348344
impl<N> Eq for Element<N> {}
349345

350-
#[cfg(feature = "nightly")]
351-
{
352-
let mut candidates = Vec::with_capacity(length.as_usize());
353-
let mut index = N::zero();
354-
while index < length {
355-
let weight = weight(index.as_usize()).into();
356-
if !(weight >= 0.) {
357-
return Err(WeightedError::InvalidWeight);
358-
}
359-
360-
let key = rng.gen::<f64>().powf(1.0 / weight);
361-
candidates.push(Element { index, key });
362-
363-
index += N::one();
346+
let mut candidates = Vec::with_capacity(length.as_usize());
347+
let mut index = N::zero();
348+
while index < length {
349+
let weight = weight(index.as_usize()).into();
350+
if !(weight >= 0.) {
351+
return Err(WeightedError::InvalidWeight);
364352
}
365353

366-
// Partially sort the array to find the `amount` elements with the greatest
367-
// keys. Do this by using `select_nth_unstable` to put the elements with
368-
// the *smallest* keys at the beginning of the list in `O(n)` time, which
369-
// provides equivalent information about the elements with the *greatest* keys.
370-
let (_, mid, greater)
371-
= candidates.select_nth_unstable(length.as_usize() - amount.as_usize());
372-
373-
let mut result: Vec<N> = Vec::with_capacity(amount.as_usize());
374-
result.push(mid.index);
375-
for element in greater {
376-
result.push(element.index);
377-
}
378-
Ok(IndexVec::from(result))
379-
}
380-
381-
#[cfg(not(feature = "nightly"))]
382-
{
383-
use alloc::collections::BinaryHeap;
354+
let key = rng.gen::<f64>().powf(1.0 / weight);
355+
candidates.push(Element { index, key });
384356

385-
// Partially sort the array such that the `amount` elements with the largest
386-
// keys are first using a binary max heap.
387-
let mut candidates = BinaryHeap::with_capacity(length.as_usize());
388-
let mut index = N::zero();
389-
while index < length {
390-
let weight = weight(index.as_usize()).into();
391-
if !(weight >= 0.) {
392-
return Err(WeightedError::InvalidWeight);
393-
}
357+
index += N::one();
358+
}
394359

395-
let key = rng.gen::<f64>().powf(1.0 / weight);
396-
candidates.push(Element { index, key });
360+
// Partially sort the array to find the `amount` elements with the greatest
361+
// keys. Do this by using `select_nth_unstable` to put the elements with
362+
// the *smallest* keys at the beginning of the list in `O(n)` time, which
363+
// provides equivalent information about the elements with the *greatest* keys.
364+
let (_, mid, greater)
365+
= candidates.select_nth_unstable(length.as_usize() - amount.as_usize());
397366

398-
index += N::one();
399-
}
400-
401-
let mut result: Vec<N> = Vec::with_capacity(amount.as_usize());
402-
while result.len() < amount.as_usize() {
403-
result.push(candidates.pop().unwrap().index);
404-
}
405-
Ok(IndexVec::from(result))
367+
let mut result: Vec<N> = Vec::with_capacity(amount.as_usize());
368+
result.push(mid.index);
369+
for element in greater {
370+
result.push(element.index);
406371
}
372+
Ok(IndexVec::from(result))
407373
}
408374

409375
/// Randomly sample exactly `amount` indices from `0..length`, using Floyd's

0 commit comments

Comments
 (0)