Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Rename doc_cfg to docsrs and use doc_auto_cfg #1450

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions rand_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions rand_core/src/blanket_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: RngCore + ?Sized> RngCore for Box<R> {
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand All @@ -63,11 +62,9 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> {
}

#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
impl<R: CryptoRng + ?Sized> CryptoRng for Box<R> {}

#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
impl<R: TryRngCore + ?Sized> TryRngCore for Box<R> {
type Error = R::Error;

Expand All @@ -88,5 +85,4 @@ impl<R: TryRngCore + ?Sized> TryRngCore for Box<R> {
}

#[cfg(feature = "alloc")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
impl<R: TryCryptoRng + ?Sized> TryCryptoRng for Box<R> {}
6 changes: 5 additions & 1 deletion rand_core/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn next_u64_via_fill<R: RngCore + ?Sized>(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<R>`, so until specialziation is stabilized, implementer crates
Expand Down Expand Up @@ -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<R>`, so until specialziation is stabilized, implementer crates
/// have to implement `TryRngCore` and `TryCryptoRng` directly.
///
/// [`TryCryptoRng`]: crate::TryCryptoRng
/// [`TryRngCore`]: crate::TryRngCore
/// [`CryptoRng`]: crate::CryptoRng
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also fixed these doc item links. We probably should setup a CI job to check doc links in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have an existing check-doc job, which should also detect bad in-repo links. Possibly we also need to deny warnings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yes.

#[macro_export]
macro_rules! impl_try_crypto_rng_from_crypto_rng {
($t:ty) => {
Expand Down
5 changes: 1 addition & 4 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand All @@ -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<Self, getrandom::Error> {
let mut seed = Self::Seed::default();
getrandom::getrandom(seed.as_mut())?;
Expand Down
1 change: 0 additions & 1 deletion rand_core/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion rand_distr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration option previously was not enabled for rand_distr.


[features]
default = ["std"]
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/cauchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Cauchy<F>
Expand Down
5 changes: 0 additions & 5 deletions rand_distr/src/dirichlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<F, const N: usize>
Expand All @@ -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`.
Expand Down Expand Up @@ -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<F, const N: usize> Dirichlet<F, N>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/exponential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: Float> Exp<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/frechet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Frechet<F>
Expand Down
4 changes: 0 additions & 4 deletions rand_distr/src/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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<F> FisherF<F>
Expand Down Expand Up @@ -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<F> Beta<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/geometric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/gumbel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Gumbel<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/hypergeometric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/inverse_gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions rand_distr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//!
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Normal<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/normal_inverse_gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/pareto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Pareto<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/pert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Pert<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/poisson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Poisson<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/skew_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> SkewNormal<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/triangular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Triangular<F>
Expand Down
1 change: 0 additions & 1 deletion rand_distr/src/weibull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F> Weibull<F>
Expand Down
2 changes: 0 additions & 2 deletions rand_distr/src/weighted_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ use serde::{Deserialize, Serialize};
/// [`Vec<u32>`]: Vec
/// [`Uniform<u32>::sample`]: Distribution::sample
/// [`Uniform<W>::sample`]: Distribution::sample
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde1",
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions rand_distr/src/weighted_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,13 @@ use serde::{Deserialize, Serialize};
/// ```
///
/// [`WeightedTreeIndex<W>`]: 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",
Copy link
Member Author

@newpavlov newpavlov May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a typo caught by the unexpected_cfgs lint.

serde(bound(deserialize = "W: Deserialize<'de>, W::Sampler: Deserialize<'de>"))
)]
#[derive(Clone, Default, Debug, PartialEq)]
Expand Down
Loading