From 890ad8b68bbb10a384a6073b47552a889da2424e Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Fri, 10 May 2024 13:46:26 +0300 Subject: [PATCH] Rename `doc_cfg` to `docsrs` and use `doc_auto_cfg` (#1450) --- Cargo.toml | 4 ++-- rand_core/Cargo.toml | 4 ++-- rand_core/src/blanket_impls.rs | 4 ---- rand_core/src/impls.rs | 6 +++++- rand_core/src/lib.rs | 5 +---- rand_core/src/os.rs | 1 - rand_distr/Cargo.toml | 2 +- rand_distr/src/binomial.rs | 1 - rand_distr/src/cauchy.rs | 1 - rand_distr/src/dirichlet.rs | 5 ----- rand_distr/src/exponential.rs | 1 - rand_distr/src/frechet.rs | 1 - rand_distr/src/gamma.rs | 4 ---- rand_distr/src/geometric.rs | 1 - rand_distr/src/gumbel.rs | 1 - rand_distr/src/hypergeometric.rs | 1 - rand_distr/src/inverse_gaussian.rs | 1 - rand_distr/src/lib.rs | 9 +-------- rand_distr/src/normal.rs | 1 - rand_distr/src/normal_inverse_gaussian.rs | 1 - rand_distr/src/pareto.rs | 1 - rand_distr/src/pert.rs | 1 - rand_distr/src/poisson.rs | 1 - rand_distr/src/skew_normal.rs | 1 - rand_distr/src/triangular.rs | 1 - rand_distr/src/weibull.rs | 1 - rand_distr/src/weighted_alias.rs | 2 -- rand_distr/src/weighted_tree.rs | 3 +-- rand_distr/src/zipf.rs | 2 -- src/distributions/distribution.rs | 1 - src/distributions/float.rs | 9 +++------ src/distributions/integer.rs | 3 --- src/distributions/mod.rs | 1 - src/distributions/other.rs | 3 --- src/distributions/slice.rs | 1 - src/distributions/uniform.rs | 10 ++-------- src/distributions/weighted_index.rs | 2 -- src/lib.rs | 7 +------ src/rngs/mod.rs | 1 - src/rngs/small.rs | 1 - src/rngs/std.rs | 1 - src/rngs/thread.rs | 8 -------- src/seq/index.rs | 1 - src/seq/mod.rs | 9 --------- 44 files changed, 19 insertions(+), 106 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a2ea562a..a0805e38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] [package.metadata.docs.rs] # To build locally: -# RUSTDOCFLAGS="--cfg doc_cfg -Zunstable-options --generate-link-to-definition" cargo +nightly doc --all --all-features --no-deps --open +# RUSTDOCFLAGS="--cfg docsrs -Zunstable-options --generate-link-to-definition" cargo +nightly doc --all --all-features --no-deps --open all-features = true -rustdoc-args = ["--cfg", "doc_cfg", "-Zunstable-options", "--generate-link-to-definition"] +rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] [package.metadata.playground] features = ["small_rng", "serde1"] diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 7c4118f6..0053b402 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -17,9 +17,9 @@ rust-version = "1.61" [package.metadata.docs.rs] # To build locally: -# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --no-deps --open +# RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --no-deps --open all-features = true -rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"] +rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] [package.metadata.playground] all-features = true diff --git a/rand_core/src/blanket_impls.rs b/rand_core/src/blanket_impls.rs index e3b54f89..754382f5 100644 --- a/rand_core/src/blanket_impls.rs +++ b/rand_core/src/blanket_impls.rs @@ -44,7 +44,6 @@ impl<'a, R: TryRngCore + ?Sized> TryRngCore for &'a mut R { impl<'a, R: TryCryptoRng + ?Sized> TryCryptoRng for &'a mut R {} #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl RngCore for Box { #[inline(always)] fn next_u32(&mut self) -> u32 { @@ -63,11 +62,9 @@ impl RngCore for Box { } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl CryptoRng for Box {} #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl TryRngCore for Box { type Error = R::Error; @@ -88,5 +85,4 @@ impl TryRngCore for Box { } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl TryCryptoRng for Box {} diff --git a/rand_core/src/impls.rs b/rand_core/src/impls.rs index ff07d783..34230e15 100644 --- a/rand_core/src/impls.rs +++ b/rand_core/src/impls.rs @@ -160,7 +160,7 @@ pub fn next_u64_via_fill(rng: &mut R) -> u64 { u64::from_le_bytes(buf) } -/// Implement [`TryRngCore`] for a type implementing [`RngCore`]. +/// Implement [`TryRngCore`][crate::TryRngCore] for a type implementing [`RngCore`]. /// /// Ideally, `rand_core` would define blanket impls for this, but they conflict with blanket impls /// for `&mut R` and `Box`, so until specialziation is stabilized, implementer crates @@ -195,6 +195,10 @@ macro_rules! impl_try_rng_from_rng_core { /// Ideally, `rand_core` would define blanket impls for this, but they conflict with blanket impls /// for `&mut R` and `Box`, so until specialziation is stabilized, implementer crates /// have to implement `TryRngCore` and `TryCryptoRng` directly. +/// +/// [`TryCryptoRng`]: crate::TryCryptoRng +/// [`TryRngCore`]: crate::TryRngCore +/// [`CryptoRng`]: crate::CryptoRng #[macro_export] macro_rules! impl_try_crypto_rng_from_crypto_rng { ($t:ty) => { diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index 48c9c528..78b7d655 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -32,8 +32,7 @@ #![deny(missing_docs)] #![deny(missing_debug_implementations)] #![doc(test(attr(allow(unused_variables), deny(warnings))))] -#![allow(unexpected_cfgs)] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![no_std] #[cfg(feature = "alloc")] @@ -446,7 +445,6 @@ pub trait SeedableRng: Sized { /// [`getrandom`]: https://docs.rs/getrandom /// [`try_from_os_rng`]: SeedableRng::try_from_os_rng #[cfg(feature = "getrandom")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] fn from_os_rng() -> Self { match Self::try_from_os_rng() { Ok(res) => res, @@ -463,7 +461,6 @@ pub trait SeedableRng: Sized { /// /// [`getrandom`]: https://docs.rs/getrandom #[cfg(feature = "getrandom")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] fn try_from_os_rng() -> Result { let mut seed = Self::Seed::default(); getrandom::getrandom(seed.as_mut())?; diff --git a/rand_core/src/os.rs b/rand_core/src/os.rs index 7d0a8ce0..86ae462e 100644 --- a/rand_core/src/os.rs +++ b/rand_core/src/os.rs @@ -44,7 +44,6 @@ use getrandom::getrandom; /// ``` /// /// [getrandom]: https://crates.io/crates/getrandom -#[cfg_attr(doc_cfg, doc(cfg(feature = "getrandom")))] #[derive(Clone, Copy, Debug, Default)] pub struct OsRng; diff --git a/rand_distr/Cargo.toml b/rand_distr/Cargo.toml index 2d23e8a9..5ca2f3d9 100644 --- a/rand_distr/Cargo.toml +++ b/rand_distr/Cargo.toml @@ -17,7 +17,7 @@ rust-version = "1.61" include = ["src/", "LICENSE-*", "README.md", "CHANGELOG.md", "COPYRIGHT"] [package.metadata.docs.rs] -rustdoc-args = ["--generate-link-to-definition"] +rustdoc-args = ["--cfg docsrs", "--generate-link-to-definition"] [features] default = ["std"] diff --git a/rand_distr/src/binomial.rs b/rand_distr/src/binomial.rs index a9e6a708..3623561e 100644 --- a/rand_distr/src/binomial.rs +++ b/rand_distr/src/binomial.rs @@ -58,7 +58,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 5a445ff8..268b5492 100644 --- a/rand_distr/src/cauchy.rs +++ b/rand_distr/src/cauchy.rs @@ -58,7 +58,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 a7e11482..ca192c01 100644 --- a/rand_distr/src/dirichlet.rs +++ b/rand_distr/src/dirichlet.rs @@ -31,7 +31,6 @@ where } /// Error type returned from `DirchletFromGamma::new`. -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum DirichletFromGammaError { /// Gamma::new(a, 1) failed. @@ -104,7 +103,6 @@ where } /// Error type returned from `DirchletFromBeta::new`. -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum DirichletFromBetaError { /// Beta::new(a, b) failed. @@ -203,7 +201,6 @@ where /// 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(feature = "serde_with", serde_as)] #[derive(Clone, Debug, PartialEq)] pub struct Dirichlet @@ -217,7 +214,6 @@ where } /// Error type returned from `Dirchlet::new`. -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Error { /// `alpha.len() < 2`. @@ -257,7 +253,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 1fa56a95..88f60d23 100644 --- a/rand_distr/src/exponential.rs +++ b/rand_distr/src/exponential.rs @@ -118,7 +118,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 781b7af1..22d7b62e 100644 --- a/rand_distr/src/frechet.rs +++ b/rand_distr/src/frechet.rs @@ -61,7 +61,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 fbafd268..8b3a3920 100644 --- a/rand_distr/src/gamma.rs +++ b/rand_distr/src/gamma.rs @@ -88,7 +88,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for Error {} #[derive(Clone, Copy, Debug, PartialEq)] @@ -311,7 +310,6 @@ impl fmt::Display for ChiSquaredError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for ChiSquaredError {} #[derive(Clone, Copy, Debug, PartialEq)] @@ -421,7 +419,6 @@ impl fmt::Display for FisherFError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for FisherFError {} impl FisherF @@ -592,7 +589,6 @@ impl fmt::Display for BetaError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 0f14d422..e4bef5cf 100644 --- a/rand_distr/src/geometric.rs +++ b/rand_distr/src/geometric.rs @@ -53,7 +53,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Geometric { diff --git a/rand_distr/src/gumbel.rs b/rand_distr/src/gumbel.rs index 4a836586..3b2e79b9 100644 --- a/rand_distr/src/gumbel.rs +++ b/rand_distr/src/gumbel.rs @@ -57,7 +57,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 84fde543..f9ffda25 100644 --- a/rand_distr/src/hypergeometric.rs +++ b/rand_distr/src/hypergeometric.rs @@ -87,7 +87,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 6518ee9e..39e53eb0 100644 --- a/rand_distr/src/inverse_gaussian.rs +++ b/rand_distr/src/inverse_gaussian.rs @@ -22,7 +22,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 ea57dd0f..0d9c6c01 100644 --- a/rand_distr/src/lib.rs +++ b/rand_distr/src/lib.rs @@ -21,8 +21,7 @@ )] #![allow(clippy::neg_cmp_op_on_partial_ord)] // suggested fix too verbose #![no_std] -#![allow(unexpected_cfgs)] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] //! Generating random samples from probability distributions. //! @@ -102,7 +101,6 @@ 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")))] 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}; @@ -130,13 +128,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")))] pub use rand::distributions::{WeightError, WeightedIndex}; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub use weighted_alias::WeightedAliasIndex; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub use weighted_tree::WeightedTreeIndex; pub use num_traits; @@ -193,10 +188,8 @@ mod test { } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub mod weighted_alias; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub mod weighted_tree; mod binomial; diff --git a/rand_distr/src/normal.rs b/rand_distr/src/normal.rs index 8ef231b0..1d427514 100644 --- a/rand_distr/src/normal.rs +++ b/rand_distr/src/normal.rs @@ -142,7 +142,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 b7988f40..18540a2b 100644 --- a/rand_distr/src/normal_inverse_gaussian.rs +++ b/rand_distr/src/normal_inverse_gaussian.rs @@ -26,7 +26,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 952afec4..8c785e5f 100644 --- a/rand_distr/src/pareto.rs +++ b/rand_distr/src/pareto.rs @@ -53,7 +53,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 48114d97..bc028e6a 100644 --- a/rand_distr/src/pert.rs +++ b/rand_distr/src/pert.rs @@ -66,7 +66,6 @@ impl fmt::Display for PertError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 5de3113d..d50769da 100644 --- a/rand_distr/src/poisson.rs +++ b/rand_distr/src/poisson.rs @@ -62,7 +62,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for Error {} impl Poisson diff --git a/rand_distr/src/skew_normal.rs b/rand_distr/src/skew_normal.rs index ad7dd2b5..908484f3 100644 --- a/rand_distr/src/skew_normal.rs +++ b/rand_distr/src/skew_normal.rs @@ -73,7 +73,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 083725f7..795a5473 100644 --- a/rand_distr/src/triangular.rs +++ b/rand_distr/src/triangular.rs @@ -64,7 +64,6 @@ impl fmt::Display for TriangularError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 2fba2a87..4d094b1f 100644 --- a/rand_distr/src/weibull.rs +++ b/rand_distr/src/weibull.rs @@ -53,7 +53,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 beb31f07..e8c455dc 100644 --- a/rand_distr/src/weighted_alias.rs +++ b/rand_distr/src/weighted_alias.rs @@ -65,7 +65,6 @@ use serde::{Deserialize, Serialize}; /// [`Vec`]: Vec /// [`Uniform::sample`]: Distribution::sample /// [`Uniform::sample`]: Distribution::sample -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde1", @@ -279,7 +278,6 @@ where /// 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")))] pub trait AliasableWeight: Sized + Copy diff --git a/rand_distr/src/weighted_tree.rs b/rand_distr/src/weighted_tree.rs index 67ce48ba..f3463bcd 100644 --- a/rand_distr/src/weighted_tree.rs +++ b/rand_distr/src/weighted_tree.rs @@ -77,14 +77,13 @@ use serde::{Deserialize, Serialize}; /// ``` /// /// [`WeightedTreeIndex`]: WeightedTreeIndex -#[cfg_attr(doc_cfg, 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 ", + feature = "serde1", serde(bound(deserialize = "W: Deserialize<'de>, W::Sampler: Deserialize<'de>")) )] #[derive(Clone, Default, Debug, PartialEq)] diff --git a/rand_distr/src/zipf.rs b/rand_distr/src/zipf.rs index 7b207a46..88848600 100644 --- a/rand_distr/src/zipf.rs +++ b/rand_distr/src/zipf.rs @@ -73,7 +73,6 @@ impl fmt::Display for ZetaError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for ZetaError {} impl Zeta @@ -181,7 +180,6 @@ impl fmt::Display for ZipfError { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, 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 2bd6a6a4..d545eeea 100644 --- a/src/distributions/distribution.rs +++ b/src/distributions/distribution.rs @@ -186,7 +186,6 @@ where /// Sampling a `String` of random characters is not quite the same as collecting /// a sequence of chars. This trait contains some helpers. #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub trait DistString { /// Append `len` random chars to `string` fn append_string(&self, rng: &mut R, string: &mut String, len: usize); diff --git a/src/distributions/float.rs b/src/distributions/float.rs index 84022685..427385e5 100644 --- a/src/distributions/float.rs +++ b/src/distributions/float.rs @@ -104,8 +104,7 @@ macro_rules! float_impls { } } - $(#[cfg($meta)] - #[cfg_attr(doc_cfg, doc(cfg($meta)))])? + $(#[cfg($meta)])? impl Distribution<$ty> for Standard { fn sample(&self, rng: &mut R) -> $ty { // Multiply-based method; 24/53 random bits; [0, 1) interval. @@ -121,8 +120,7 @@ macro_rules! float_impls { } } - $(#[cfg($meta)] - #[cfg_attr(doc_cfg, doc(cfg($meta)))])? + $(#[cfg($meta)])? impl Distribution<$ty> for OpenClosed01 { fn sample(&self, rng: &mut R) -> $ty { // Multiply-based method; 24/53 random bits; (0, 1] interval. @@ -139,8 +137,7 @@ macro_rules! float_impls { } } - $(#[cfg($meta)] - #[cfg_attr(doc_cfg, doc(cfg($meta)))])? + $(#[cfg($meta)])? impl Distribution<$ty> for Open01 { fn sample(&self, rng: &mut R) -> $ty { // Transmute-based method; 23/52 random bits; (0, 1) interval. diff --git a/src/distributions/integer.rs b/src/distributions/integer.rs index 60bcbf95..66258dcb 100644 --- a/src/distributions/integer.rs +++ b/src/distributions/integer.rs @@ -127,7 +127,6 @@ impl_nzint!(NonZeroIsize, NonZeroIsize::new); macro_rules! x86_intrinsic_impl { ($meta:meta, $($intrinsic:ident),+) => {$( #[cfg($meta)] - #[cfg_attr(doc_cfg, doc(cfg($meta)))] impl Distribution<$intrinsic> for Standard { #[inline] fn sample(&self, rng: &mut R) -> $intrinsic { @@ -149,8 +148,6 @@ macro_rules! simd_impl { /// /// [`simd_support`]: https://github.com/rust-random/rand#crate-features #[cfg(feature = "simd_support")] - // TODO: as doc_cfg/doc_auto_cfg mature ensure they catch this - #[cfg_attr(doc_cfg, doc(cfg(feature = "simd_support")))] impl Distribution> for Standard where LaneCount: SupportedLaneCount, diff --git a/src/distributions/mod.rs b/src/distributions/mod.rs index e5973297..b31ebe14 100644 --- a/src/distributions/mod.rs +++ b/src/distributions/mod.rs @@ -111,7 +111,6 @@ pub mod uniform; pub use self::bernoulli::{Bernoulli, BernoulliError}; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub use self::distribution::DistString; pub use self::distribution::{DistIter, DistMap, Distribution}; pub use self::float::{Open01, OpenClosed01}; diff --git a/src/distributions/other.rs b/src/distributions/other.rs index 15ccf30a..21289ca9 100644 --- a/src/distributions/other.rs +++ b/src/distributions/other.rs @@ -96,7 +96,6 @@ impl Distribution for Standard { /// Note: the `String` is potentially left with excess capacity; optionally the /// user may call `string.shrink_to_fit()` afterwards. #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl DistString for Standard { fn append_string(&self, rng: &mut R, s: &mut String, len: usize) { // A char is encoded with at most four bytes, thus this reservation is @@ -127,7 +126,6 @@ impl Distribution for Alphanumeric { } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl DistString for Alphanumeric { fn append_string(&self, rng: &mut R, string: &mut String, len: usize) { unsafe { @@ -175,7 +173,6 @@ impl Distribution for Standard { /// [`_mm_blendv_epi8`]: https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_blendv_epi8&ig_expand=514/ /// [`simd_support`]: https://github.com/rust-random/rand#crate-features #[cfg(feature = "simd_support")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "simd_support")))] impl Distribution> for Standard where T: MaskElement + Default, diff --git a/src/distributions/slice.rs b/src/distributions/slice.rs index 88cff889..10f830b7 100644 --- a/src/distributions/slice.rs +++ b/src/distributions/slice.rs @@ -129,7 +129,6 @@ impl std::error::Error for EmptySlice {} /// Note: the `String` is potentially left with excess capacity; optionally the /// user may call `string.shrink_to_fit()` afterwards. #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl<'a> super::DistString for Slice<'a, char> { fn append_string(&self, rng: &mut R, string: &mut String, len: usize) { // Get the max char length to minimize extra space. diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index fde8d6db..34a6b252 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -140,7 +140,6 @@ impl fmt::Display for Error { } #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl std::error::Error for Error {} #[cfg(feature = "serde1")] @@ -676,7 +675,6 @@ macro_rules! uniform_simd_int_impl { // implement it manually. #[cfg(feature = "simd_support")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "simd_support")))] impl SampleUniform for Simd<$ty, LANES> where LaneCount: SupportedLaneCount, @@ -688,7 +686,6 @@ macro_rules! uniform_simd_int_impl { } #[cfg(feature = "simd_support")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "simd_support")))] impl UniformSampler for UniformInt> where LaneCount: SupportedLaneCount, @@ -864,7 +861,6 @@ impl UniformSampler for UniformChar { /// includes non ascii chars; optionally the user may call /// `string.shrink_to_fit()` afterwards. #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl super::DistString for Uniform { fn append_string( &self, @@ -912,14 +908,12 @@ pub struct UniformFloat { macro_rules! uniform_float_impl { ($($meta:meta)?, $ty:ty, $uty:ident, $f_scalar:ident, $u_scalar:ident, $bits_to_discard:expr) => { - $(#[cfg($meta)] - #[cfg_attr(doc_cfg, doc(cfg($meta)))])? + $(#[cfg($meta)])? impl SampleUniform for $ty { type Sampler = UniformFloat<$ty>; } - $(#[cfg($meta)] - #[cfg_attr(doc_cfg, doc(cfg($meta)))])? + $(#[cfg($meta)])? impl UniformSampler for UniformFloat<$ty> { type X = $ty; diff --git a/src/distributions/weighted_index.rs b/src/distributions/weighted_index.rs index a0213766..ec3bbade 100644 --- a/src/distributions/weighted_index.rs +++ b/src/distributions/weighted_index.rs @@ -82,7 +82,6 @@ use serde::{Deserialize, Serialize}; /// [`RngCore`]: crate::RngCore #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub struct WeightedIndex { cumulative_weights: Vec, total_weight: X, @@ -702,7 +701,6 @@ mod test { } /// Errors returned by weighted distributions -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum WeightError { /// The input weight sequence is empty, too long, or wrongly ordered diff --git a/src/lib.rs b/src/lib.rs index 3e8ab5c7..8b43f032 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,8 +50,7 @@ #![doc(test(attr(allow(unused_variables), deny(warnings))))] #![no_std] #![cfg_attr(feature = "simd_support", feature(portable_simd))] -#![allow(unexpected_cfgs)] -#![cfg_attr(doc_cfg, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![allow( clippy::float_cmp, clippy::neg_cmp_op_on_partial_ord, @@ -157,10 +156,6 @@ use crate::distributions::{Distribution, Standard}; /// [`Standard`]: distributions::Standard /// [`ThreadRng`]: rngs::ThreadRng #[cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))] -#[cfg_attr( - doc_cfg, - doc(cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))) -)] #[inline] pub fn random() -> T where diff --git a/src/rngs/mod.rs b/src/rngs/mod.rs index 0aa6c427..413d61bf 100644 --- a/src/rngs/mod.rs +++ b/src/rngs/mod.rs @@ -121,6 +121,5 @@ pub use self::std::StdRng; #[cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))] pub use self::thread::ThreadRng; -#[cfg_attr(doc_cfg, 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 12276885..b53e3443 100644 --- a/src/rngs/small.rs +++ b/src/rngs/small.rs @@ -38,7 +38,6 @@ type Rng = super::xoshiro128plusplus::Xoshiro128PlusPlus; /// [`StdRng`]: crate::rngs::StdRng /// [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")))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct SmallRng(Rng); diff --git a/src/rngs/std.rs b/src/rngs/std.rs index 34a6fa8c..57b9bfef 100644 --- a/src/rngs/std.rs +++ b/src/rngs/std.rs @@ -30,7 +30,6 @@ 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")))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct StdRng(Rng); diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index f9f1a0af..161b5d6e 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -76,10 +76,6 @@ const THREAD_RNG_RESEED_THRESHOLD: u64 = 1024 * 64; /// /// [`ReseedingRng`]: crate::rngs::ReseedingRng /// [`StdRng`]: crate::rngs::StdRng -#[cfg_attr( - doc_cfg, - doc(cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))) -)] #[derive(Clone)] pub struct ThreadRng { // Rc is explicitly !Send and !Sync @@ -135,10 +131,6 @@ thread_local!( /// println!("A simulated die roll: {}", rng.gen_range(1..=6)); /// # } /// ``` -#[cfg_attr( - doc_cfg, - doc(cfg(all(feature = "std", feature = "std_rng", feature = "getrandom"))) -)] 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 9ef6bf89..42b810f0 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -282,7 +282,6 @@ where /// /// This implementation uses `O(length + amount)` space and `O(length)` time. #[cfg(feature = "std")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] pub fn sample_weighted( rng: &mut R, length: usize, diff --git a/src/seq/mod.rs b/src/seq/mod.rs index 1df250d0..d8268e9a 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -28,7 +28,6 @@ mod coin_flipper; #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] pub mod index; mod increasing_uniform; @@ -122,7 +121,6 @@ pub trait IndexedRandom: Index { /// } /// ``` #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] fn choose_multiple(&self, rng: &mut R, amount: usize) -> SliceChooseIter where Self::Output: Sized, @@ -166,7 +164,6 @@ pub trait IndexedRandom: Index { /// [`choose_weighted_mut`]: IndexedMutRandom::choose_weighted_mut /// [`distributions::WeightedIndex`]: crate::distributions::WeightedIndex #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] fn choose_weighted( &self, rng: &mut R, @@ -218,7 +215,6 @@ pub trait IndexedRandom: Index { // 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")))] fn choose_multiple_weighted( &self, rng: &mut R, @@ -288,7 +284,6 @@ pub trait IndexedMutRandom: IndexedRandom + IndexMut { /// [`choose_weighted`]: IndexedRandom::choose_weighted /// [`distributions::WeightedIndex`]: crate::distributions::WeightedIndex #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] fn choose_weighted_mut( &mut self, rng: &mut R, @@ -585,7 +580,6 @@ pub trait IteratorRandom: Iterator + Sized { /// Complexity is `O(n)` where `n` is the length of the iterator. /// For slices, prefer [`IndexedRandom::choose_multiple`]. #[cfg(feature = "alloc")] - #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] fn choose_multiple(mut self, rng: &mut R, amount: usize) -> Vec where R: Rng + ?Sized, @@ -672,7 +666,6 @@ impl IteratorRandom for I where I: Iterator + Sized {} /// This struct is created by /// [`IndexedRandom::choose_multiple`](trait.IndexedRandom.html#tymethod.choose_multiple). #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] #[derive(Debug)] pub struct SliceChooseIter<'a, S: ?Sized + 'a, T: 'a> { slice: &'a S, @@ -681,7 +674,6 @@ pub struct SliceChooseIter<'a, S: ?Sized + 'a, T: 'a> { } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl<'a, S: Index + ?Sized + 'a, T: 'a> Iterator for SliceChooseIter<'a, S, T> { type Item = &'a T; @@ -696,7 +688,6 @@ impl<'a, S: Index + ?Sized + 'a, T: 'a> Iterator for SliceCho } #[cfg(feature = "alloc")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] impl<'a, S: Index + ?Sized + 'a, T: 'a> ExactSizeIterator for SliceChooseIter<'a, S, T> {