diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml deleted file mode 100644 index 80c0ec3d965..00000000000 --- a/.github/workflows/gh-pages.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: gh-pages - -on: - push: - branches: - - master - -jobs: - deploy: - name: GH-pages documentation - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Install toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - name: doc (rand) - env: - RUSTDOCFLAGS: --cfg doc_cfg - # --all builds all crates, but with default features for other crates (okay in this case) - run: | - cargo doc --all --features nightly,serde1,getrandom,small_rng - cp utils/redirect.html target/doc/index.html - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./target/doc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..131590b3ade --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,18 @@ +name: Publish to crates.io and create GitHub release +on: + push: + tags: ['[0-9].[0-9].*', '[0-9].[1-9][0-9].*'] +jobs: + # Source: https://crates.io/docs/trusted-publishing + publish: + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + steps: + - uses: actions/checkout@v6 + - uses: rust-lang/crates-io-auth-action@v1 + id: auth + - run: cargo publish + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e90e380645..b827791ba83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,6 +78,10 @@ jobs: cargo test --target ${{ matrix.target }} --benches --features=nightly cargo test --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --benches cargo test --target ${{ matrix.target }} --lib --tests --no-default-features --features min_const_gen + - name: Use Cargo.lock.msrv (1.36) + if: ${{ matrix.toolchain == '1.36.0' }} + run: | + cp Cargo.lock.msrv Cargo.lock - name: Test rand run: | cargo test --target ${{ matrix.target }} --lib --tests --no-default-features @@ -87,12 +91,12 @@ jobs: - name: Test rand (all stable features, non-MSRV) if: ${{ matrix.toolchain != '1.36.0' }} run: | - cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng,min_const_gen + cargo test --target ${{ matrix.target }} --features=serde1,small_rng,min_const_gen - name: Test rand (all stable features, MSRV) if: ${{ matrix.toolchain == '1.36.0' }} run: | # const generics are not stable on 1.36.0 - cargo test --target ${{ matrix.target }} --features=serde1,log,small_rng + cargo test --target ${{ matrix.target }} --features=serde1,small_rng - name: Test rand_core run: | cargo test --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml @@ -115,20 +119,18 @@ jobs: matrix: include: - os: ubuntu-latest - target: mips-unknown-linux-gnu + target: powerpc-unknown-linux-gnu toolchain: stable steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v6 - name: Install toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal target: ${{ matrix.target }} toolchain: ${{ matrix.toolchain }} - override: true - name: Cache cargo plugins - uses: actions/cache@v1 + uses: actions/cache@v5 with: path: ~/.cargo/bin/ key: ${{ runner.os }}-cargo-plugins @@ -137,7 +139,7 @@ jobs: - name: Test run: | # all stable features: - cross test --no-fail-fast --target ${{ matrix.target }} --features=serde1,log,small_rng + cross test --no-fail-fast --target ${{ matrix.target }} --features=serde1,small_rng cross test --no-fail-fast --target ${{ matrix.target }} --examples cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_core/Cargo.toml cross test --no-fail-fast --target ${{ matrix.target }} --manifest-path rand_distr/Cargo.toml --features=serde1 @@ -156,7 +158,7 @@ jobs: - name: Test rand run: | cargo miri test --no-default-features --lib --tests - cargo miri test --features=log,small_rng + cargo miri test --features=small_rng cargo miri test --manifest-path rand_core/Cargo.toml cargo miri test --manifest-path rand_core/Cargo.toml --features=serde1 cargo miri test --manifest-path rand_core/Cargo.toml --no-default-features diff --git a/CHANGELOG.md b/CHANGELOG.md index b0872af6d39..56b04ea11f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,17 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md). You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful. +## [0.8.6] - 2026-04-14 +This release back-ports a fix from v0.10. See also [#1763]. + +### Changes +- Deprecate feature `log` ([#1772]) + +[#1763]: https://github.com/rust-random/rand/pull/1763 +[#1772]: https://github.com/rust-random/rand/pull/1772 + +- Drop the experimental `simd_support` feature. + ## [0.8.5] - 2021-08-20 ### Fixes - Fix build on non-32/64-bit architectures (#1144) diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv new file mode 100644 index 00000000000..285d0291712 --- /dev/null +++ b/Cargo.lock.msrv @@ -0,0 +1,233 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "average" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "easy-cast 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "float-ord 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "easy-cast" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libm 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "float-ord" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.138 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.11.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.138" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libm" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libm 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "proc-macro2" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-ident 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.8.6" +dependencies = [ + "bincode 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.138 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "rand_pcg 0.3.1", + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +dependencies = [ + "ppv-lite86 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.6.4", + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +dependencies = [ + "getrandom 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_distr" +version = "0.4.3" +dependencies = [ + "average 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.8.6", + "rand_pcg 0.3.1", + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", + "special 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_pcg" +version = "0.3.1" +dependencies = [ + "bincode 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.6.4", + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.65 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.105 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_json" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "itoa 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "special" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.138 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "1.0.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.65 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum autocfg 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +"checksum average 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "843ec791d3f24503bbf72bbd5e49a3ab4dbb4bcd0a8ef6b0c908efa73caa27b1" +"checksum bincode 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +"checksum cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +"checksum easy-cast 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bd102ee8c418348759919b83b81cdbdc933ffe29740b903df448b4bafaa348e" +"checksum float-ord 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d" +"checksum getrandom 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +"checksum itoa 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +"checksum libc 0.2.138 (registry+https://github.com/rust-lang/crates.io-index)" = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" +"checksum libm 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" +"checksum num-traits 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +"checksum ppv-lite86 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +"checksum proc-macro2 1.0.65 (registry+https://github.com/rust-lang/crates.io-index)" = "92de25114670a878b1261c79c9f8f729fb97e95bac93f6312f583c60dd6a1dfe" +"checksum quote 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +"checksum ryu 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +"checksum serde 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)" = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" +"checksum serde_derive 1.0.149 (registry+https://github.com/rust-lang/crates.io-index)" = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4" +"checksum serde_json 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +"checksum special 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "24a65e074159b75dcf173a4733ab2188baac24967b5c8ec9ed87ae15fcbc7636" +"checksum syn 1.0.105 (registry+https://github.com/rust-lang/crates.io-index)" = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +"checksum unicode-ident 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +"checksum wasi 0.11.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/Cargo.toml b/Cargo.toml index 98ba373c68f..a0ad6cc695e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand" -version = "0.8.5" +version = "0.8.6" authors = ["The Rand Project Developers", "The Rust Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -18,9 +18,9 @@ include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] [package.metadata.docs.rs] # To build locally: -# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open +# RUSTDOCFLAGS="--cfg docsrs -Zunstable-options --generate-link-to-definition" cargo +nightly doc --all --features serde1,getrandom,small_rng,min_const_gen --no-deps" all-features = true -rustdoc-args = ["--cfg", "doc_cfg"] +rustdoc-args = ["--generate-link-to-definition"] [package.metadata.playground] features = ["small_rng", "serde1"] @@ -41,9 +41,6 @@ alloc = ["rand_core/alloc"] # Option: use getrandom package for seeding getrandom = ["rand_core/getrandom"] -# Option (requires nightly): experimental SIMD support -simd_support = ["packed_simd"] - # Option (enabled by default): enable StdRng std_rng = ["rand_chacha"] @@ -54,6 +51,10 @@ small_rng = [] # using min-const-generics min_const_gen = [] +# Option: enabled logging. This is deprecated; Rand no longer logs +# anything. +log = [] + [workspace] members = [ "rand_core", @@ -64,17 +65,9 @@ members = [ [dependencies] rand_core = { path = "rand_core", version = "0.6.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 } -[dependencies.packed_simd] -# NOTE: so far no version works reliably due to dependence on unstable features -package = "packed_simd_2" -version = "0.3.7" -optional = true -features = ["into_bits"] - [target.'cfg(unix)'.dependencies] # Used for fork protection (reseeding.rs) libc = { version = "0.2.22", optional = true, default-features = false } diff --git a/README.md b/README.md index 44c2e4d518e..619ddecb82d 100644 --- a/README.md +++ b/README.md @@ -118,22 +118,16 @@ Rand is built with these features enabled by default: - `std_rng` enables inclusion of `StdRng`, `thread_rng` and `random` (the latter two *also* require that `std` be enabled) -Optionally, the following dependencies can be enabled: - -- `log` enables logging via the `log` crate - Additionally, these features configure Rand: - `small_rng` enables inclusion of the `SmallRng` PRNG - `nightly` enables some optimizations requiring nightly Rust -- `simd_support` (experimental) enables sampling of SIMD values - (uniformly random SIMD integers and floats), requiring nightly Rust - `min_const_gen` enables generating random arrays of any size using min-const-generics, requiring Rust ≥ 1.51. Note that nightly features are not stable and therefore not all library and compiler versions will be compatible. This is especially true of Rand's -experimental `simd_support` feature. +experimental `simd_support` feature, which was dropped by version 0.8.6 of Rand. Rand supports limited functionality in `no_std` mode (enabled via `default-features = false`). In this case, `OsRng` and `from_entropy` are diff --git a/rand_core/src/error.rs b/rand_core/src/error.rs index 411896f2c47..592d009370e 100644 --- a/rand_core/src/error.rs +++ b/rand_core/src/error.rs @@ -47,7 +47,7 @@ impl Error { /// /// See also `From`, which is available with and without `std`. #[cfg(feature = "std")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] + #[cfg_attr(docsrs, doc(cfg(feature = "std")))] #[inline] pub fn new(err: E) -> Self where @@ -61,7 +61,7 @@ impl Error { /// When configured with `std`, this is a trivial operation and never /// panics. Without `std`, this method is simply unavailable. #[cfg(feature = "std")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] + #[cfg_attr(docsrs, doc(cfg(feature = "std")))] #[inline] pub fn inner(&self) -> &(dyn std::error::Error + Send + Sync + 'static) { &*self.inner @@ -72,7 +72,7 @@ impl Error { /// When configured with `std`, this is a trivial operation and never /// panics. Without `std`, this method is simply unavailable. #[cfg(feature = "std")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] + #[cfg_attr(docsrs, doc(cfg(feature = "std")))] #[inline] pub fn take_inner(self) -> Box { self.inner diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index fdbf6675b96..aaa7f99ecf1 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -35,7 +35,7 @@ #![deny(missing_docs)] #![deny(missing_debug_implementations)] #![doc(test(attr(allow(unused_variables), deny(warnings))))] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![no_std] use core::convert::AsMut; @@ -288,6 +288,9 @@ pub trait SeedableRng: Sized { /// MyRng(seed) /// } /// } + /// + /// # let rng = MyRng::from_seed(Default::default()); + /// # let _ = rng.0; /// ``` type Seed: Sized + Default + AsMut<[u8]>; @@ -408,7 +411,7 @@ pub trait SeedableRng: Sized { /// /// [`getrandom`]: https://docs.rs/getrandom #[cfg(feature = "getrandom")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] + #[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] fn from_entropy() -> Self { let mut seed = Self::Seed::default(); if let Err(err) = getrandom::getrandom(seed.as_mut()) { diff --git a/rand_core/src/os.rs b/rand_core/src/os.rs index 6cd1b9cf5de..4c532ed79c7 100644 --- a/rand_core/src/os.rs +++ b/rand_core/src/os.rs @@ -43,7 +43,7 @@ use getrandom::getrandom; /// ``` /// /// [getrandom]: https://crates.io/crates/getrandom -#[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] +#[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] #[derive(Clone, Copy, Debug, Default)] pub struct OsRng; diff --git a/rand_distr/src/binomial.rs b/rand_distr/src/binomial.rs index 6dbf7ab7494..0bbdd778565 100644 --- a/rand_distr/src/binomial.rs +++ b/rand_distr/src/binomial.rs @@ -58,7 +58,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Binomial { diff --git a/rand_distr/src/cauchy.rs b/rand_distr/src/cauchy.rs index 9aff7e625f4..040a010f4e4 100644 --- a/rand_distr/src/cauchy.rs +++ b/rand_distr/src/cauchy.rs @@ -56,7 +56,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Cauchy diff --git a/rand_distr/src/dirichlet.rs b/rand_distr/src/dirichlet.rs index 786cbccd0cc..94e85d5b41d 100644 --- a/rand_distr/src/dirichlet.rs +++ b/rand_distr/src/dirichlet.rs @@ -31,7 +31,7 @@ use alloc::{boxed::Box, vec, vec::Vec}; /// let samples = dirichlet.sample(&mut rand::thread_rng()); /// println!("{:?} is from a Dirichlet([1.0, 2.0, 3.0]) distribution", samples); /// ``` -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub struct Dirichlet @@ -46,7 +46,7 @@ where } /// Error type returned from `Dirchlet::new`. -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Error { /// `alpha.len() < 2`. @@ -69,7 +69,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Dirichlet diff --git a/rand_distr/src/exponential.rs b/rand_distr/src/exponential.rs index e3d2a8d1cf6..33fa39ecf37 100644 --- a/rand_distr/src/exponential.rs +++ b/rand_distr/src/exponential.rs @@ -116,7 +116,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Exp diff --git a/rand_distr/src/frechet.rs b/rand_distr/src/frechet.rs index 63205b40cbd..88ad1dec349 100644 --- a/rand_distr/src/frechet.rs +++ b/rand_distr/src/frechet.rs @@ -61,7 +61,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Frechet diff --git a/rand_distr/src/gamma.rs b/rand_distr/src/gamma.rs index debad0c8438..22b36e9a6b1 100644 --- a/rand_distr/src/gamma.rs +++ b/rand_distr/src/gamma.rs @@ -88,7 +88,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} #[derive(Clone, Copy, Debug, PartialEq)] @@ -311,7 +311,7 @@ impl fmt::Display for ChiSquaredError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for ChiSquaredError {} #[derive(Clone, Copy, Debug, PartialEq)] @@ -421,7 +421,7 @@ impl fmt::Display for FisherFError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for FisherFError {} impl FisherF @@ -591,7 +591,7 @@ impl fmt::Display for BetaError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for BetaError {} impl Beta diff --git a/rand_distr/src/geometric.rs b/rand_distr/src/geometric.rs index 3ea8b8f3e13..3eb74c9ad6c 100644 --- a/rand_distr/src/geometric.rs +++ b/rand_distr/src/geometric.rs @@ -52,7 +52,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Geometric { @@ -143,7 +143,7 @@ impl Distribution for Geometric /// /// See [`Geometric`](crate::Geometric) for the general geometric distribution. /// -/// Implemented via iterated [Rng::gen::().leading_zeros()]. +/// Implemented via iterated `Rng::gen::().leading_zeros()`. /// /// # Example /// ``` diff --git a/rand_distr/src/gumbel.rs b/rand_distr/src/gumbel.rs index b254919f3b8..365c848df37 100644 --- a/rand_distr/src/gumbel.rs +++ b/rand_distr/src/gumbel.rs @@ -57,7 +57,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Gumbel diff --git a/rand_distr/src/hypergeometric.rs b/rand_distr/src/hypergeometric.rs index 4761450360d..e5c4d4fb4de 100644 --- a/rand_distr/src/hypergeometric.rs +++ b/rand_distr/src/hypergeometric.rs @@ -78,7 +78,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} // evaluate fact(numerator.0)*fact(numerator.1) / fact(denominator.0)*fact(denominator.1) diff --git a/rand_distr/src/inverse_gaussian.rs b/rand_distr/src/inverse_gaussian.rs index ba845fd1505..3c6b036efaa 100644 --- a/rand_distr/src/inverse_gaussian.rs +++ b/rand_distr/src/inverse_gaussian.rs @@ -22,7 +22,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} /// The [inverse Gaussian distribution](https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution) diff --git a/rand_distr/src/lib.rs b/rand_distr/src/lib.rs index 6d8d81bd2f3..0a618ff8575 100644 --- a/rand_distr/src/lib.rs +++ b/rand_distr/src/lib.rs @@ -20,7 +20,7 @@ )] #![allow(clippy::neg_cmp_op_on_partial_ord)] // suggested fix too verbose #![no_std] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] //! Generating random samples from probability distributions. //! @@ -99,7 +99,7 @@ pub use rand::distributions::{ pub use self::binomial::{Binomial, Error as BinomialError}; pub use self::cauchy::{Cauchy, Error as CauchyError}; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub use self::dirichlet::{Dirichlet, Error as DirichletError}; pub use self::exponential::{Error as ExpError, Exp, Exp1}; pub use self::frechet::{Error as FrechetError, Frechet}; @@ -127,10 +127,10 @@ pub use self::unit_sphere::UnitSphere; pub use self::weibull::{Error as WeibullError, Weibull}; pub use self::zipf::{Zeta, ZetaError, Zipf, ZipfError}; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub use rand::distributions::{WeightedError, WeightedIndex}; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub use weighted_alias::WeightedAliasIndex; pub use num_traits; @@ -183,7 +183,7 @@ mod test { } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub mod weighted_alias; mod binomial; diff --git a/rand_distr/src/normal.rs b/rand_distr/src/normal.rs index b3b801dfed9..9e94c71f760 100644 --- a/rand_distr/src/normal.rs +++ b/rand_distr/src/normal.rs @@ -140,7 +140,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Normal diff --git a/rand_distr/src/normal_inverse_gaussian.rs b/rand_distr/src/normal_inverse_gaussian.rs index e05d5b09ef3..8a5e86de892 100644 --- a/rand_distr/src/normal_inverse_gaussian.rs +++ b/rand_distr/src/normal_inverse_gaussian.rs @@ -22,7 +22,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} /// The [normal-inverse Gaussian distribution](https://en.wikipedia.org/wiki/Normal-inverse_Gaussian_distribution) diff --git a/rand_distr/src/pareto.rs b/rand_distr/src/pareto.rs index 25c8e0537dd..aaea44e5f9b 100644 --- a/rand_distr/src/pareto.rs +++ b/rand_distr/src/pareto.rs @@ -51,7 +51,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Pareto diff --git a/rand_distr/src/pert.rs b/rand_distr/src/pert.rs index db89fff7bfb..eaf9b4cfd34 100644 --- a/rand_distr/src/pert.rs +++ b/rand_distr/src/pert.rs @@ -66,7 +66,7 @@ impl fmt::Display for PertError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for PertError {} impl Pert diff --git a/rand_distr/src/poisson.rs b/rand_distr/src/poisson.rs index 8b9bffd020e..6c7be6f2b30 100644 --- a/rand_distr/src/poisson.rs +++ b/rand_distr/src/poisson.rs @@ -57,7 +57,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Poisson @@ -183,4 +183,4 @@ mod test { fn poisson_distributions_can_be_compared() { assert_eq!(Poisson::new(1.0), Poisson::new(1.0)); } -} \ No newline at end of file +} diff --git a/rand_distr/src/skew_normal.rs b/rand_distr/src/skew_normal.rs index 146b4ead125..3b6a762c2ec 100644 --- a/rand_distr/src/skew_normal.rs +++ b/rand_distr/src/skew_normal.rs @@ -73,7 +73,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl SkewNormal diff --git a/rand_distr/src/triangular.rs b/rand_distr/src/triangular.rs index eef7d190133..dd5e9c3100e 100644 --- a/rand_distr/src/triangular.rs +++ b/rand_distr/src/triangular.rs @@ -62,7 +62,7 @@ impl fmt::Display for TriangularError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for TriangularError {} impl Triangular diff --git a/rand_distr/src/weibull.rs b/rand_distr/src/weibull.rs index fe45eff6613..fe7cd00a250 100644 --- a/rand_distr/src/weibull.rs +++ b/rand_distr/src/weibull.rs @@ -51,7 +51,7 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Weibull diff --git a/rand_distr/src/weighted_alias.rs b/rand_distr/src/weighted_alias.rs index 582a4dd9ba8..1032b52f485 100644 --- a/rand_distr/src/weighted_alias.rs +++ b/rand_distr/src/weighted_alias.rs @@ -65,7 +65,7 @@ use serde::{Serialize, Deserialize}; /// [`Vec`]: Vec /// [`Uniform::sample`]: Distribution::sample /// [`Uniform::sample`]: Distribution::sample -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde1", serde(bound(serialize = "W: Serialize, W::Sampler: Serialize")))] #[cfg_attr(feature = "serde1", serde(bound(deserialize = "W: Deserialize<'de>, W::Sampler: Deserialize<'de>")))] @@ -275,7 +275,7 @@ where Uniform: Clone /// Trait that must be implemented for weights, that are used with /// [`WeightedAliasIndex`]. Currently no guarantees on the correctness of /// [`WeightedAliasIndex`] are given for custom implementations of this trait. -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub trait AliasableWeight: Sized + Copy diff --git a/rand_distr/src/zipf.rs b/rand_distr/src/zipf.rs index 84d33c052e1..e793170f7cd 100644 --- a/rand_distr/src/zipf.rs +++ b/rand_distr/src/zipf.rs @@ -70,7 +70,7 @@ impl fmt::Display for ZetaError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for ZetaError {} impl Zeta @@ -170,7 +170,7 @@ impl fmt::Display for ZipfError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for ZipfError {} impl Zipf diff --git a/src/distributions/distribution.rs b/src/distributions/distribution.rs index c5cf6a607b4..4cf7350f0a5 100644 --- a/src/distributions/distribution.rs +++ b/src/distributions/distribution.rs @@ -159,8 +159,8 @@ where { } -#[cfg(features = "nightly")] -impl iter::TrustedLen for DistIter +#[cfg(feature = "nightly")] +unsafe impl iter::TrustedLen for DistIter where D: Distribution, R: Rng, diff --git a/src/distributions/float.rs b/src/distributions/float.rs index ce5946f7f01..dd9f25cdcd8 100644 --- a/src/distributions/float.rs +++ b/src/distributions/float.rs @@ -12,7 +12,6 @@ use crate::distributions::utils::FloatSIMDUtils; use crate::distributions::{Distribution, Standard}; use crate::Rng; use core::mem; -#[cfg(feature = "simd_support")] use packed_simd::*; #[cfg(feature = "serde1")] use serde::{Serialize, Deserialize}; @@ -153,22 +152,6 @@ macro_rules! float_impls { float_impls! { f32, u32, f32, u32, 23, 127 } float_impls! { f64, u64, f64, u64, 52, 1023 } -#[cfg(feature = "simd_support")] -float_impls! { f32x2, u32x2, f32, u32, 23, 127 } -#[cfg(feature = "simd_support")] -float_impls! { f32x4, u32x4, f32, u32, 23, 127 } -#[cfg(feature = "simd_support")] -float_impls! { f32x8, u32x8, f32, u32, 23, 127 } -#[cfg(feature = "simd_support")] -float_impls! { f32x16, u32x16, f32, u32, 23, 127 } - -#[cfg(feature = "simd_support")] -float_impls! { f64x2, u64x2, f64, u64, 52, 1023 } -#[cfg(feature = "simd_support")] -float_impls! { f64x4, u64x4, f64, u64, 52, 1023 } -#[cfg(feature = "simd_support")] -float_impls! { f64x8, u64x8, f64, u64, 52, 1023 } - #[cfg(test)] mod tests { @@ -209,14 +192,6 @@ mod tests { }; } test_f32! { f32_edge_cases, f32, 0.0, EPSILON32 } - #[cfg(feature = "simd_support")] - test_f32! { f32x2_edge_cases, f32x2, f32x2::splat(0.0), f32x2::splat(EPSILON32) } - #[cfg(feature = "simd_support")] - test_f32! { f32x4_edge_cases, f32x4, f32x4::splat(0.0), f32x4::splat(EPSILON32) } - #[cfg(feature = "simd_support")] - test_f32! { f32x8_edge_cases, f32x8, f32x8::splat(0.0), f32x8::splat(EPSILON32) } - #[cfg(feature = "simd_support")] - test_f32! { f32x16_edge_cases, f32x16, f32x16::splat(0.0), f32x16::splat(EPSILON32) } macro_rules! test_f64 { ($fnn:ident, $ty:ident, $ZERO:expr, $EPSILON:expr) => { @@ -249,12 +224,6 @@ mod tests { }; } test_f64! { f64_edge_cases, f64, 0.0, EPSILON64 } - #[cfg(feature = "simd_support")] - test_f64! { f64x2_edge_cases, f64x2, f64x2::splat(0.0), f64x2::splat(EPSILON64) } - #[cfg(feature = "simd_support")] - test_f64! { f64x4_edge_cases, f64x4, f64x4::splat(0.0), f64x4::splat(EPSILON64) } - #[cfg(feature = "simd_support")] - test_f64! { f64x8_edge_cases, f64x8, f64x8::splat(0.0), f64x8::splat(EPSILON64) } #[test] fn value_stability() { @@ -289,24 +258,5 @@ mod tests { 0.20298547462974248, 0.8166436635290656, ]); - - #[cfg(feature = "simd_support")] - { - // We only test a sub-set of types here. Values are identical to - // non-SIMD types; we assume this pattern continues across all - // SIMD types. - - test_samples(&Standard, f32x2::new(0.0, 0.0), &[ - f32x2::new(0.0035963655, 0.7346052), - f32x2::new(0.09778172, 0.20298547), - f32x2::new(0.34296435, 0.81664366), - ]); - - test_samples(&Standard, f64x2::new(0.0, 0.0), &[ - f64x2::new(0.7346051961657583, 0.20298547462974248), - f64x2::new(0.8166436635290655, 0.7423708925400552), - f64x2::new(0.16387782224016323, 0.9087068770169618), - ]); - } } } diff --git a/src/distributions/integer.rs b/src/distributions/integer.rs index 19ce71599cb..936996b33ff 100644 --- a/src/distributions/integer.rs +++ b/src/distributions/integer.rs @@ -10,13 +10,8 @@ use crate::distributions::{Distribution, Standard}; use crate::Rng; -#[cfg(all(target_arch = "x86", feature = "simd_support"))] -use core::arch::x86::{__m128i, __m256i}; -#[cfg(all(target_arch = "x86_64", feature = "simd_support"))] -use core::arch::x86_64::{__m128i, __m256i}; use core::num::{NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, NonZeroU128}; -#[cfg(feature = "simd_support")] use packed_simd::*; impl Distribution for Standard { #[inline] @@ -109,54 +104,6 @@ impl_nzint!(NonZeroU64, NonZeroU64::new); impl_nzint!(NonZeroU128, NonZeroU128::new); impl_nzint!(NonZeroUsize, NonZeroUsize::new); -#[cfg(feature = "simd_support")] -macro_rules! simd_impl { - ($(($intrinsic:ident, $vec:ty),)+) => {$( - impl Distribution<$intrinsic> for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> $intrinsic { - $intrinsic::from_bits(rng.gen::<$vec>()) - } - } - )+}; - - ($bits:expr,) => {}; - ($bits:expr, $ty:ty, $($ty_more:ty,)*) => { - simd_impl!($bits, $($ty_more,)*); - - impl Distribution<$ty> for Standard { - #[inline] - fn sample(&self, rng: &mut R) -> $ty { - let mut vec: $ty = Default::default(); - unsafe { - let ptr = &mut vec; - let b_ptr = &mut *(ptr as *mut $ty as *mut [u8; $bits/8]); - rng.fill_bytes(b_ptr); - } - vec.to_le() - } - } - }; -} - -#[cfg(feature = "simd_support")] -simd_impl!(16, u8x2, i8x2,); -#[cfg(feature = "simd_support")] -simd_impl!(32, u8x4, i8x4, u16x2, i16x2,); -#[cfg(feature = "simd_support")] -simd_impl!(64, u8x8, i8x8, u16x4, i16x4, u32x2, i32x2,); -#[cfg(feature = "simd_support")] -simd_impl!(128, u8x16, i8x16, u16x8, i16x8, u32x4, i32x4, u64x2, i64x2,); -#[cfg(feature = "simd_support")] -simd_impl!(256, u8x32, i8x32, u16x16, i16x16, u32x8, i32x8, u64x4, i64x4,); -#[cfg(feature = "simd_support")] -simd_impl!(512, u8x64, i8x64, u16x32, i16x32, u32x16, i32x16, u64x8, i64x8,); -#[cfg(all( - feature = "simd_support", - any(target_arch = "x86", target_arch = "x86_64") -))] -simd_impl!((__m128i, u8x16), (__m256i, u8x32),); - #[cfg(test)] mod tests { use super::*; @@ -216,59 +163,5 @@ mod tests { test_samples(0i8, &[9, -9, 111]); // Skip further i* types: they are simple reinterpretation of u* samples - - #[cfg(feature = "simd_support")] - { - // We only test a sub-set of types here and make assumptions about the rest. - - test_samples(u8x2::default(), &[ - u8x2::new(9, 126), - u8x2::new(247, 167), - u8x2::new(111, 149), - ]); - test_samples(u8x4::default(), &[ - u8x4::new(9, 126, 87, 132), - u8x4::new(247, 167, 123, 153), - u8x4::new(111, 149, 73, 120), - ]); - test_samples(u8x8::default(), &[ - u8x8::new(9, 126, 87, 132, 247, 167, 123, 153), - u8x8::new(111, 149, 73, 120, 68, 171, 98, 223), - u8x8::new(24, 121, 1, 50, 13, 46, 164, 20), - ]); - - test_samples(i64x8::default(), &[ - i64x8::new( - -7387126082252079607, - -2350127744969763473, - 1487364411147516184, - 7895421560427121838, - 602190064936008898, - 6022086574635100741, - -5080089175222015595, - -4066367846667249123, - ), - i64x8::new( - 9180885022207963908, - 3095981199532211089, - 6586075293021332726, - 419343203796414657, - 3186951873057035255, - 5287129228749947252, - 444726432079249540, - -1587028029513790706, - ), - i64x8::new( - 6075236523189346388, - 1351763722368165432, - -6192309979959753740, - -7697775502176768592, - -4482022114172078123, - 7522501477800909500, - -1837258847956201231, - -586926753024886735, - ), - ]); - } } } diff --git a/src/distributions/mod.rs b/src/distributions/mod.rs index 05ca80606b0..d2270bd1ef2 100644 --- a/src/distributions/mod.rs +++ b/src/distributions/mod.rs @@ -54,16 +54,16 @@ //! space to be specified as an arbitrary range within its target type `T`. //! Both [`Standard`] and [`Uniform`] are in some sense uniform distributions. //! -//! Values may be sampled from this distribution using [`Rng::sample(Range)`] or +//! Values may be sampled from this distribution using `Rng::sample(Range)` or //! by creating a distribution object with [`Uniform::new`], //! [`Uniform::new_inclusive`] or `From`. When the range limits are not //! known at compile time it is typically faster to reuse an existing -//! `Uniform` object than to call [`Rng::sample(Range)`]. +//! `Uniform` object than to call `Rng::sample(Range)`. //! //! User types `T` may also implement `Distribution` for [`Uniform`], //! although this is less straightforward than for [`Standard`] (see the //! documentation in the [`uniform`] module). Doing so enables generation of -//! values of type `T` with [`Rng::sample(Range)`]. +//! values of type `T` with `Rng::sample(Range)`. //! //! ## Open and half-open ranges //! @@ -113,7 +113,7 @@ pub mod uniform; note = "use rand::distributions::{WeightedIndex, WeightedError} instead" )] #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub mod weighted; pub use self::bernoulli::{Bernoulli, BernoulliError}; diff --git a/src/distributions/other.rs b/src/distributions/other.rs index 03802a76d5f..5436f315354 100644 --- a/src/distributions/other.rs +++ b/src/distributions/other.rs @@ -190,7 +190,7 @@ tuple_impl! {A, B, C, D, E, F, G, H, I, J, K} tuple_impl! {A, B, C, D, E, F, G, H, I, J, K, L} #[cfg(feature = "min_const_gen")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "min_const_gen")))] +#[cfg_attr(docsrs, doc(cfg(feature = "min_const_gen")))] impl Distribution<[T; N]> for Standard where Standard: Distribution { diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 261357b2456..284bf8db027 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -53,7 +53,7 @@ //! `low < high`). The example below merely wraps another back-end. //! //! The `new`, `new_inclusive` and `sample_single` functions use arguments of -//! type SampleBorrow in order to support passing in values by reference or +//! type `SampleBorrow` in order to support passing in values by reference or //! by value. In the implementation of these functions, you can choose to //! simply use the reference returned by [`SampleBorrow::borrow`], or you can choose //! to copy or clone the value, whatever is appropriate for your type. @@ -118,8 +118,6 @@ use crate::{Rng, RngCore}; #[allow(unused_imports)] // rustc doesn't detect that this is actually used use crate::distributions::utils::Float; -#[cfg(feature = "simd_support")] use packed_simd::*; - #[cfg(feature = "serde1")] use serde::{Serialize, Deserialize}; @@ -569,151 +567,6 @@ uniform_int_impl! { u64, u64, u64 } uniform_int_impl! { usize, usize, usize } uniform_int_impl! { u128, u128, u128 } -#[cfg(feature = "simd_support")] -macro_rules! uniform_simd_int_impl { - ($ty:ident, $unsigned:ident, $u_scalar:ident) => { - // The "pick the largest zone that can fit in an `u32`" optimization - // is less useful here. Multiple lanes complicate things, we don't - // know the PRNG's minimal output size, and casting to a larger vector - // is generally a bad idea for SIMD performance. The user can still - // implement it manually. - - // TODO: look into `Uniform::::new(0u32, 100)` functionality - // perhaps `impl SampleUniform for $u_scalar`? - impl SampleUniform for $ty { - type Sampler = UniformInt<$ty>; - } - - impl UniformSampler for UniformInt<$ty> { - type X = $ty; - - #[inline] // if the range is constant, this helps LLVM to do the - // calculations at compile-time. - fn new(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.lt(high).all(), "Uniform::new called with `low >= high`"); - UniformSampler::new_inclusive(low, high - 1) - } - - #[inline] // if the range is constant, this helps LLVM to do the - // calculations at compile-time. - fn new_inclusive(low_b: B1, high_b: B2) -> Self - where B1: SampleBorrow + Sized, - B2: SampleBorrow + Sized - { - let low = *low_b.borrow(); - let high = *high_b.borrow(); - assert!(low.le(high).all(), - "Uniform::new_inclusive called with `low > high`"); - let unsigned_max = ::core::$u_scalar::MAX; - - // NOTE: these may need to be replaced with explicitly - // wrapping operations if `packed_simd` changes - let range: $unsigned = ((high - low) + 1).cast(); - // `% 0` will panic at runtime. - let not_full_range = range.gt($unsigned::splat(0)); - // replacing 0 with `unsigned_max` allows a faster `select` - // with bitwise OR - let modulo = not_full_range.select(range, $unsigned::splat(unsigned_max)); - // wrapping addition - let ints_to_reject = (unsigned_max - range + 1) % modulo; - // When `range` is 0, `lo` of `v.wmul(range)` will always be - // zero which means only one sample is needed. - let zone = unsigned_max - ints_to_reject; - - UniformInt { - low, - // These are really $unsigned values, but store as $ty: - range: range.cast(), - z: zone.cast(), - } - } - - fn sample(&self, rng: &mut R) -> Self::X { - let range: $unsigned = self.range.cast(); - let zone: $unsigned = self.z.cast(); - - // This might seem very slow, generating a whole new - // SIMD vector for every sample rejection. For most uses - // though, the chance of rejection is small and provides good - // general performance. With multiple lanes, that chance is - // multiplied. To mitigate this, we replace only the lanes of - // the vector which fail, iteratively reducing the chance of - // rejection. The replacement method does however add a little - // overhead. Benchmarking or calculating probabilities might - // reveal contexts where this replacement method is slower. - let mut v: $unsigned = rng.gen(); - loop { - let (hi, lo) = v.wmul(range); - let mask = lo.le(zone); - if mask.all() { - let hi: $ty = hi.cast(); - // wrapping addition - let result = self.low + hi; - // `select` here compiles to a blend operation - // When `range.eq(0).none()` the compare and blend - // operations are avoided. - let v: $ty = v.cast(); - return range.gt($unsigned::splat(0)).select(result, v); - } - // Replace only the failing lanes - v = mask.select(v, rng.gen()); - } - } - } - }; - - // bulk implementation - ($(($unsigned:ident, $signed:ident),)+ $u_scalar:ident) => { - $( - uniform_simd_int_impl!($unsigned, $unsigned, $u_scalar); - uniform_simd_int_impl!($signed, $unsigned, $u_scalar); - )+ - }; -} - -#[cfg(feature = "simd_support")] -uniform_simd_int_impl! { - (u64x2, i64x2), - (u64x4, i64x4), - (u64x8, i64x8), - u64 -} - -#[cfg(feature = "simd_support")] -uniform_simd_int_impl! { - (u32x2, i32x2), - (u32x4, i32x4), - (u32x8, i32x8), - (u32x16, i32x16), - u32 -} - -#[cfg(feature = "simd_support")] -uniform_simd_int_impl! { - (u16x2, i16x2), - (u16x4, i16x4), - (u16x8, i16x8), - (u16x16, i16x16), - (u16x32, i16x32), - u16 -} - -#[cfg(feature = "simd_support")] -uniform_simd_int_impl! { - (u8x2, i8x2), - (u8x4, i8x4), - (u8x8, i8x8), - (u8x16, i8x16), - (u8x32, i8x32), - (u8x64, i8x64), - u8 -} - impl SampleUniform for char { type Sampler = UniformChar; } @@ -998,23 +851,6 @@ macro_rules! uniform_float_impl { uniform_float_impl! { f32, u32, f32, u32, 32 - 23 } uniform_float_impl! { f64, u64, f64, u64, 64 - 52 } -#[cfg(feature = "simd_support")] -uniform_float_impl! { f32x2, u32x2, f32, u32, 32 - 23 } -#[cfg(feature = "simd_support")] -uniform_float_impl! { f32x4, u32x4, f32, u32, 32 - 23 } -#[cfg(feature = "simd_support")] -uniform_float_impl! { f32x8, u32x8, f32, u32, 32 - 23 } -#[cfg(feature = "simd_support")] -uniform_float_impl! { f32x16, u32x16, f32, u32, 32 - 23 } - -#[cfg(feature = "simd_support")] -uniform_float_impl! { f64x2, u64x2, f64, u64, 64 - 52 } -#[cfg(feature = "simd_support")] -uniform_float_impl! { f64x4, u64x4, f64, u64, 64 - 52 } -#[cfg(feature = "simd_support")] -uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 } - - /// The back-end implementing [`UniformSampler`] for `Duration`. /// /// Unless you are implementing [`UniformSampler`] for your own types, this type @@ -1295,18 +1131,6 @@ mod tests { }}; } t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, i128, u128); - - #[cfg(feature = "simd_support")] - { - t!(u8x2, u8x4, u8x8, u8x16, u8x32, u8x64 => u8); - t!(i8x2, i8x4, i8x8, i8x16, i8x32, i8x64 => i8); - t!(u16x2, u16x4, u16x8, u16x16, u16x32 => u16); - t!(i16x2, i16x4, i16x8, i16x16, i16x32 => i16); - t!(u32x2, u32x4, u32x8, u32x16 => u32); - t!(i32x2, i32x4, i32x8, i32x16 => i32); - t!(u64x2, u64x4, u64x8 => u64); - t!(i64x2, i64x4, i64x8 => i64); - } } #[test] @@ -1415,16 +1239,6 @@ mod tests { t!(f32, f32, 32 - 23); t!(f64, f64, 64 - 52); - #[cfg(feature = "simd_support")] - { - t!(f32x2, f32, 32 - 23); - t!(f32x4, f32, 32 - 23); - t!(f32x8, f32, 32 - 23); - t!(f32x16, f32, 32 - 23); - t!(f64x2, f64, 64 - 52); - t!(f64x4, f64, 64 - 52); - t!(f64x8, f64, 64 - 52); - } } #[test] @@ -1444,7 +1258,6 @@ mod tests { #[cfg(all( feature = "std", not(target_arch = "wasm32"), - not(target_arch = "asmjs") ))] fn test_float_assertions() { use super::SampleUniform; @@ -1489,16 +1302,6 @@ mod tests { t!(f32, f32); t!(f64, f64); - #[cfg(feature = "simd_support")] - { - t!(f32x2, f32); - t!(f32x4, f32); - t!(f32x8, f32); - t!(f32x16, f32); - t!(f64x2, f64); - t!(f64x4, f64); - t!(f64x8, f64); - } } diff --git a/src/distributions/utils.rs b/src/distributions/utils.rs index 89da5fd7aad..c852bb0254a 100644 --- a/src/distributions/utils.rs +++ b/src/distributions/utils.rs @@ -8,8 +8,6 @@ //! Math helper functions -#[cfg(feature = "simd_support")] use packed_simd::*; - pub(crate) trait WideningMultiply { type Output; @@ -141,69 +139,6 @@ wmul_impl_usize! { u32 } #[cfg(target_pointer_width = "64")] wmul_impl_usize! { u64 } -#[cfg(feature = "simd_support")] -mod simd_wmul { - use super::*; - #[cfg(target_arch = "x86")] use core::arch::x86::*; - #[cfg(target_arch = "x86_64")] use core::arch::x86_64::*; - - wmul_impl! { - (u8x2, u16x2), - (u8x4, u16x4), - (u8x8, u16x8), - (u8x16, u16x16), - (u8x32, u16x32),, - 8 - } - - wmul_impl! { (u16x2, u32x2),, 16 } - wmul_impl! { (u16x4, u32x4),, 16 } - #[cfg(not(target_feature = "sse2"))] - wmul_impl! { (u16x8, u32x8),, 16 } - #[cfg(not(target_feature = "avx2"))] - wmul_impl! { (u16x16, u32x16),, 16 } - - // 16-bit lane widths allow use of the x86 `mulhi` instructions, which - // means `wmul` can be implemented with only two instructions. - #[allow(unused_macros)] - macro_rules! wmul_impl_16 { - ($ty:ident, $intrinsic:ident, $mulhi:ident, $mullo:ident) => { - impl WideningMultiply for $ty { - type Output = ($ty, $ty); - - #[inline(always)] - fn wmul(self, x: $ty) -> Self::Output { - let b = $intrinsic::from_bits(x); - let a = $intrinsic::from_bits(self); - let hi = $ty::from_bits(unsafe { $mulhi(a, b) }); - let lo = $ty::from_bits(unsafe { $mullo(a, b) }); - (hi, lo) - } - } - }; - } - - #[cfg(target_feature = "sse2")] - wmul_impl_16! { u16x8, __m128i, _mm_mulhi_epu16, _mm_mullo_epi16 } - #[cfg(target_feature = "avx2")] - wmul_impl_16! { u16x16, __m256i, _mm256_mulhi_epu16, _mm256_mullo_epi16 } - // FIXME: there are no `__m512i` types in stdsimd yet, so `wmul::` - // cannot use the same implementation. - - wmul_impl! { - (u32x2, u64x2), - (u32x4, u64x4), - (u32x8, u64x8),, - 32 - } - - // TODO: optimize, this seems to seriously slow things down - wmul_impl_large! { (u8x64,) u8, 4 } - wmul_impl_large! { (u16x32,) u16, 8 } - wmul_impl_large! { (u32x16,) u32, 16 } - wmul_impl_large! { (u64x2, u64x4, u64x8,) u64, 32 } -} - /// Helper trait when dealing with scalar and SIMD floating point types. pub(crate) trait FloatSIMDUtils { // `PartialOrd` for vectors compares lexicographically. We want to compare all @@ -232,7 +167,8 @@ pub(crate) trait FloatSIMDUtils { } /// Implement functions available in std builds but missing from core primitives -#[cfg(not(std))] +#[cfg(not(feature = "std"))] +#[allow(unused)] // False positive: We are following `std` here. #[allow(clippy::wrong_self_convention)] pub(crate) trait Float: Sized { @@ -242,6 +178,7 @@ pub(crate) trait Float: Sized { } /// Implement functions on f32/f64 to give them APIs similar to SIMD types +#[allow(unused)] pub(crate) trait FloatAsSIMD: Sized { #[inline(always)] fn lanes() -> usize { @@ -263,6 +200,7 @@ pub(crate) trait FloatAsSIMD: Sized { } } +#[allow(unused)] pub(crate) trait BoolAsSIMD: Sized { fn any(self) -> bool; fn all(self) -> bool; @@ -288,7 +226,7 @@ impl BoolAsSIMD for bool { macro_rules! scalar_float_impl { ($ty:ident, $uty:ident) => { - #[cfg(not(std))] + #[cfg(not(feature = "std"))] impl Float for $ty { #[inline] fn is_nan(self) -> bool { @@ -358,72 +296,3 @@ macro_rules! scalar_float_impl { scalar_float_impl!(f32, u32); scalar_float_impl!(f64, u64); - - -#[cfg(feature = "simd_support")] -macro_rules! simd_impl { - ($ty:ident, $f_scalar:ident, $mty:ident, $uty:ident) => { - impl FloatSIMDUtils for $ty { - type Mask = $mty; - type UInt = $uty; - - #[inline(always)] - fn all_lt(self, other: Self) -> bool { - self.lt(other).all() - } - - #[inline(always)] - fn all_le(self, other: Self) -> bool { - self.le(other).all() - } - - #[inline(always)] - fn all_finite(self) -> bool { - self.finite_mask().all() - } - - #[inline(always)] - fn finite_mask(self) -> Self::Mask { - // This can possibly be done faster by checking bit patterns - let neg_inf = $ty::splat(::core::$f_scalar::NEG_INFINITY); - let pos_inf = $ty::splat(::core::$f_scalar::INFINITY); - self.gt(neg_inf) & self.lt(pos_inf) - } - - #[inline(always)] - fn gt_mask(self, other: Self) -> Self::Mask { - self.gt(other) - } - - #[inline(always)] - fn ge_mask(self, other: Self) -> Self::Mask { - self.ge(other) - } - - #[inline(always)] - fn decrease_masked(self, mask: Self::Mask) -> Self { - // Casting a mask into ints will produce all bits set for - // true, and 0 for false. Adding that to the binary - // representation of a float means subtracting one from - // the binary representation, resulting in the next lower - // value representable by $ty. This works even when the - // current value is infinity. - debug_assert!(mask.any(), "At least one lane must be set"); - <$ty>::from_bits(<$uty>::from_bits(self) + <$uty>::from_bits(mask)) - } - - #[inline] - fn cast_from_int(i: Self::UInt) -> Self { - i.cast() - } - } - }; -} - -#[cfg(feature="simd_support")] simd_impl! { f32x2, f32, m32x2, u32x2 } -#[cfg(feature="simd_support")] simd_impl! { f32x4, f32, m32x4, u32x4 } -#[cfg(feature="simd_support")] simd_impl! { f32x8, f32, m32x8, u32x8 } -#[cfg(feature="simd_support")] simd_impl! { f32x16, f32, m32x16, u32x16 } -#[cfg(feature="simd_support")] simd_impl! { f64x2, f64, m64x2, u64x2 } -#[cfg(feature="simd_support")] simd_impl! { f64x4, f64, m64x4, u64x4 } -#[cfg(feature="simd_support")] simd_impl! { f64x8, f64, m64x8, u64x8 } diff --git a/src/distributions/weighted_index.rs b/src/distributions/weighted_index.rs index 8252b172f7f..f22773a1b91 100644 --- a/src/distributions/weighted_index.rs +++ b/src/distributions/weighted_index.rs @@ -77,7 +77,7 @@ use serde::{Serialize, Deserialize}; /// [`RngCore`]: crate::RngCore #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub struct WeightedIndex { cumulative_weights: Vec, total_weight: X, @@ -426,7 +426,7 @@ mod test { } /// Error type returned from `WeightedIndex::new`. -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum WeightedError { /// The provided weight collection contains no items. diff --git a/src/lib.rs b/src/lib.rs index 6d847180111..d7705c054bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,8 +49,8 @@ #![deny(missing_debug_implementations)] #![doc(test(attr(allow(unused_variables), deny(warnings))))] #![no_std] -#![cfg_attr(feature = "simd_support", feature(stdsimd))] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(feature = "nightly", feature(trusted_len))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![allow( clippy::float_cmp, clippy::neg_cmp_op_on_partial_ord, @@ -59,37 +59,6 @@ #[cfg(feature = "std")] extern crate std; #[cfg(feature = "alloc")] extern crate alloc; -#[allow(unused)] -macro_rules! trace { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::trace!($($x)*) - } -) } -#[allow(unused)] -macro_rules! debug { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::debug!($($x)*) - } -) } -#[allow(unused)] -macro_rules! info { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::info!($($x)*) - } -) } -#[allow(unused)] -macro_rules! warn { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::warn!($($x)*) - } -) } -#[allow(unused)] -macro_rules! error { ($($x:tt)*) => ( - #[cfg(feature = "log")] { - log::error!($($x)*) - } -) } - // Re-exports from rand_core pub use rand_core::{CryptoRng, Error, RngCore, SeedableRng}; @@ -178,7 +147,7 @@ use crate::distributions::{Distribution, Standard}; /// /// [`Standard`]: distributions::Standard #[cfg(all(feature = "std", feature = "std_rng"))] -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", feature = "std_rng"))))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "std_rng"))))] #[inline] pub fn random() -> T where Standard: Distribution { diff --git a/src/rng.rs b/src/rng.rs index 79a9fbff46e..9fe0ebf150a 100644 --- a/src/rng.rs +++ b/src/rng.rs @@ -392,7 +392,7 @@ macro_rules! impl_fill { impl_fill!(u16, u32, u64, usize, u128,); impl_fill!(i8, i16, i32, i64, isize, i128,); -#[cfg_attr(doc_cfg, doc(cfg(feature = "min_const_gen")))] +#[cfg_attr(docsrs, doc(cfg(feature = "min_const_gen")))] #[cfg(feature = "min_const_gen")] impl Fill for [T; N] where [T]: Fill diff --git a/src/rngs/adapter/reseeding.rs b/src/rngs/adapter/reseeding.rs index ae3fcbb2fc2..21177039f7c 100644 --- a/src/rngs/adapter/reseeding.rs +++ b/src/rngs/adapter/reseeding.rs @@ -241,18 +241,10 @@ where fn reseed_and_generate( &mut self, results: &mut ::Results, global_fork_counter: usize, ) { - #![allow(clippy::if_same_then_else)] // false positive - if self.is_forked(global_fork_counter) { - info!("Fork detected, reseeding RNG"); - } else { - trace!("Reseeding RNG (periodic reseed)"); - } - let num_bytes = results.as_ref().len() * size_of::<::Item>(); if let Err(e) = self.reseed() { - warn!("Reseeding RNG failed: {}", e); - let _ = e; + panic!("Reseeding RNG failed: {}", e); } self.fork_counter = global_fork_counter; diff --git a/src/rngs/mod.rs b/src/rngs/mod.rs index ac3c2c595da..9fa5e70ebca 100644 --- a/src/rngs/mod.rs +++ b/src/rngs/mod.rs @@ -96,7 +96,7 @@ //! [`rand_xoshiro`]: https://crates.io/crates/rand_xoshiro //! [`rng` tag]: https://crates.io/keywords/rng -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] #[cfg(feature = "std")] pub mod adapter; pub mod mock; // Public so we don't export `StepRng` directly, making it a bit @@ -115,5 +115,5 @@ mod xoshiro128plusplus; #[cfg(feature = "std_rng")] pub use self::std::StdRng; #[cfg(all(feature = "std", feature = "std_rng"))] pub use self::thread::ThreadRng; -#[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] +#[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] #[cfg(feature = "getrandom")] pub use rand_core::OsRng; diff --git a/src/rngs/small.rs b/src/rngs/small.rs index fb0e0d119b6..7aa968a1884 100644 --- a/src/rngs/small.rs +++ b/src/rngs/small.rs @@ -76,7 +76,7 @@ type Rng = super::xoshiro128plusplus::Xoshiro128PlusPlus; /// [`thread_rng`]: crate::thread_rng /// [rand_chacha]: https://crates.io/crates/rand_chacha /// [rand_xoshiro]: https://crates.io/crates/rand_xoshiro -#[cfg_attr(doc_cfg, doc(cfg(feature = "small_rng")))] +#[cfg_attr(docsrs, doc(cfg(feature = "small_rng")))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct SmallRng(Rng); diff --git a/src/rngs/std.rs b/src/rngs/std.rs index cdae8fab01c..6deafe0d723 100644 --- a/src/rngs/std.rs +++ b/src/rngs/std.rs @@ -29,7 +29,7 @@ use rand_chacha::ChaCha12Rng as Rng; /// /// [rand_chacha]: https://crates.io/crates/rand_chacha /// [rand issue]: https://github.com/rust-random/rand/issues/932 -#[cfg_attr(doc_cfg, doc(cfg(feature = "std_rng")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std_rng")))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct StdRng(Rng); diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index baebb1d99c7..aae10e4fbe0 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -57,7 +57,7 @@ const THREAD_RNG_RESEED_THRESHOLD: u64 = 1024 * 64; /// /// [`ReseedingRng`]: crate::rngs::adapter::ReseedingRng /// [`StdRng`]: crate::rngs::StdRng -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", feature = "std_rng"))))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "std_rng"))))] #[derive(Clone, Debug)] pub struct ThreadRng { // Rc is explicitly !Send and !Sync @@ -84,7 +84,7 @@ thread_local!( /// `ThreadRng::default()` equivalent. /// /// For more information see [`ThreadRng`]. -#[cfg_attr(doc_cfg, doc(cfg(all(feature = "std", feature = "std_rng"))))] +#[cfg_attr(docsrs, doc(cfg(all(feature = "std", feature = "std_rng"))))] pub fn thread_rng() -> ThreadRng { let rng = THREAD_RNG_KEY.with(|t| t.clone()); ThreadRng { rng } diff --git a/src/seq/index.rs b/src/seq/index.rs index b38e4649d1f..a71fb46cf01 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -273,7 +273,7 @@ where R: Rng + ?Sized { /// /// Panics if `amount > length`. #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn sample_weighted( rng: &mut R, length: usize, weight: F, amount: usize, ) -> Result diff --git a/src/seq/mod.rs b/src/seq/mod.rs index 069e9e6b19e..100cb19511f 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -26,7 +26,7 @@ #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub mod index; #[cfg(feature = "alloc")] use core::ops::Index; @@ -111,8 +111,8 @@ pub trait SliceRandom { /// } /// ``` #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] - fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter + #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] + fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter<'_, Self, Self::Item> where R: Rng + ?Sized; /// Similar to [`choose`], but where the likelihood of each outcome may be @@ -139,7 +139,7 @@ pub trait SliceRandom { /// [`choose_weighted_mut`]: SliceRandom::choose_weighted_mut /// [`distributions::weighted`]: crate::distributions::weighted #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] + #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] fn choose_weighted( &self, rng: &mut R, weight: F, ) -> Result<&Self::Item, WeightedError> @@ -167,7 +167,7 @@ pub trait SliceRandom { /// [`choose_weighted`]: SliceRandom::choose_weighted /// [`distributions::weighted`]: crate::distributions::weighted #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] + #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] fn choose_weighted_mut( &mut self, rng: &mut R, weight: F, ) -> Result<&mut Self::Item, WeightedError> @@ -216,10 +216,10 @@ pub trait SliceRandom { // Note: this is feature-gated on std due to usage of f64::powf. // If necessary, we may use alloc+libm as an alternative (see PR #1089). #[cfg(feature = "std")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] + #[cfg_attr(docsrs, doc(cfg(feature = "std")))] fn choose_multiple_weighted( &self, rng: &mut R, amount: usize, weight: F, - ) -> Result, WeightedError> + ) -> Result, WeightedError> where R: Rng + ?Sized, F: Fn(&Self::Item) -> X, @@ -462,7 +462,7 @@ pub trait IteratorRandom: Iterator + Sized { /// Complexity is `O(n)` where `n` is the length of the iterator. /// For slices, prefer [`SliceRandom::choose_multiple`]. #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] + #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] fn choose_multiple(mut self, rng: &mut R, amount: usize) -> Vec where R: Rng + ?Sized { let mut reservoir = Vec::with_capacity(amount); @@ -512,7 +512,7 @@ impl SliceRandom for [T] { } #[cfg(feature = "alloc")] - fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter + fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter<'_, Self, Self::Item> where R: Rng + ?Sized { let amount = ::core::cmp::min(amount, self.len()); SliceChooseIter { @@ -563,7 +563,7 @@ impl SliceRandom for [T] { #[cfg(feature = "std")] fn choose_multiple_weighted( &self, rng: &mut R, amount: usize, weight: F, - ) -> Result, WeightedError> + ) -> Result, WeightedError> where R: Rng + ?Sized, F: Fn(&Self::Item) -> X, @@ -620,7 +620,7 @@ impl IteratorRandom for I where I: Iterator + Sized {} /// This struct is created by /// [`SliceRandom::choose_multiple`](trait.SliceRandom.html#tymethod.choose_multiple). #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] #[derive(Debug)] pub struct SliceChooseIter<'a, S: ?Sized + 'a, T: 'a> { slice: &'a S,