Skip to content

Commit 6e02f15

Browse files
authored
Configure docs for feature gates globally (#1565)
In #1479 we used `cfg_attr(docsrs, doc(cfg(feature = "...")))` to add feature-gating information to the documentation. However, this required us to "remember" this at every call site. It turns out that there is a `doc(auto_cfg)` setting that we can use globally to do this for us automatically.
1 parent d573745 commit 6e02f15

File tree

9 files changed

+1
-23
lines changed

9 files changed

+1
-23
lines changed

src/array_approx.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#[cfg(feature = "approx")]
2-
#[cfg_attr(docsrs, doc(cfg(feature = "approx")))]
32
mod approx_methods
43
{
54
use crate::imp_prelude::*;
@@ -244,5 +243,4 @@ macro_rules! impl_approx_traits {
244243
}
245244

246245
#[cfg(feature = "approx")]
247-
#[cfg_attr(docsrs, doc(cfg(feature = "approx")))]
248246
impl_approx_traits!(approx, "**Requires crate feature `\"approx\"`.**");

src/arraytraits.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ unsafe impl<A, D> Sync for ArrayRef<A, D> where A: Sync {}
507507
unsafe impl<A, D> Send for ArrayRef<A, D> where A: Send {}
508508

509509
#[cfg(feature = "serde")]
510-
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
511510
// Use version number so we can add a packed format later.
512511
pub const ARRAY_FORMAT_VERSION: u8 = 1u8;
513512

src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impl PartialEq for ShapeError
8181
}
8282

8383
#[cfg(feature = "std")]
84-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
8584
impl Error for ShapeError {}
8685

8786
impl fmt::Display for ShapeError

src/impl_constructors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ where S: DataOwned<Elem = A>
9999
/// assert!(array == arr1(&[0.0, 0.25, 0.5, 0.75, 1.0]))
100100
/// ```
101101
#[cfg(feature = "std")]
102-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
103102
pub fn linspace(start: A, end: A, n: usize) -> Self
104103
where A: Float
105104
{
@@ -118,7 +117,6 @@ where S: DataOwned<Elem = A>
118117
/// assert!(array == arr1(&[0., 1., 2., 3., 4.]))
119118
/// ```
120119
#[cfg(feature = "std")]
121-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
122120
pub fn range(start: A, end: A, step: A) -> Self
123121
where A: Float
124122
{
@@ -147,7 +145,6 @@ where S: DataOwned<Elem = A>
147145
/// # }
148146
/// ```
149147
#[cfg(feature = "std")]
150-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
151148
pub fn logspace(base: A, start: A, end: A, n: usize) -> Self
152149
where A: Float
153150
{
@@ -182,7 +179,6 @@ where S: DataOwned<Elem = A>
182179
/// # example().unwrap();
183180
/// ```
184181
#[cfg(feature = "std")]
185-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
186182
pub fn geomspace(start: A, end: A, n: usize) -> Option<Self>
187183
where A: Float
188184
{

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![cfg_attr(not(feature = "std"), no_std)]
2323
// Enable the doc_cfg nightly feature for including feature gate flags in the documentation
2424
#![cfg_attr(docsrs, feature(doc_cfg))]
25+
#![cfg_attr(docsrs, doc(auto_cfg))]
2526
#![warn(missing_docs)]
2627

2728
//! The `ndarray` crate provides an *n*-dimensional container for general elements
@@ -158,7 +159,6 @@ use crate::iterators::{ElementsBase, ElementsBaseMut};
158159
pub use crate::arraytraits::AsArray;
159160
pub use crate::linalg_traits::LinalgScalar;
160161
#[cfg(feature = "std")]
161-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
162162
pub use crate::linalg_traits::NdFloat;
163163

164164
pub use crate::stacking::{concatenate, stack};
@@ -201,11 +201,9 @@ mod layout;
201201
mod linalg_traits;
202202
mod linspace;
203203
#[cfg(feature = "std")]
204-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
205204
pub use crate::linspace::{linspace, range, Linspace};
206205
mod logspace;
207206
#[cfg(feature = "std")]
208-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
209207
pub use crate::logspace::{logspace, Logspace};
210208
mod math_cell;
211209
mod numeric_util;
@@ -1842,7 +1840,6 @@ where
18421840

18431841
// parallel methods
18441842
#[cfg(feature = "rayon")]
1845-
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
18461843
pub mod parallel;
18471844

18481845
mod impl_1d;

src/linalg_traits.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl<T> LinalgScalar for T where T: 'static + Copy + Zero + One + Add<Output = T
4242
///
4343
/// **Requires default crate feature `"std"`**
4444
#[cfg(feature = "std")]
45-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
4645
pub trait NdFloat:
4746
Float
4847
+ AddAssign
@@ -62,8 +61,6 @@ pub trait NdFloat:
6261
}
6362

6463
#[cfg(feature = "std")]
65-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
6664
impl NdFloat for f32 {}
6765
#[cfg(feature = "std")]
68-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
6966
impl NdFloat for f64 {}

src/numeric/impl_float_maths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ macro_rules! binary_ops {
5454
///
5555
/// Element-wise math functions for any array type that contains float number.
5656
#[cfg(feature = "std")]
57-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
5857
impl<A, D> ArrayRef<A, D>
5958
where
6059
A: 'static + Float,

src/numeric/impl_numeric.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ where D: Dimension
177177
/// ```
178178
#[track_caller]
179179
#[cfg(feature = "std")]
180-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
181180
pub fn var(&self, ddof: A) -> A
182181
where A: Float + FromPrimitive
183182
{
@@ -243,7 +242,6 @@ where D: Dimension
243242
/// ```
244243
#[track_caller]
245244
#[cfg(feature = "std")]
246-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
247245
pub fn std(&self, ddof: A) -> A
248246
where A: Float + FromPrimitive
249247
{
@@ -400,7 +398,6 @@ where D: Dimension
400398
/// ```
401399
#[track_caller]
402400
#[cfg(feature = "std")]
403-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
404401
pub fn var_axis(&self, axis: Axis, ddof: A) -> Array<A, D::Smaller>
405402
where
406403
A: Float + FromPrimitive,
@@ -471,7 +468,6 @@ where D: Dimension
471468
/// ```
472469
#[track_caller]
473470
#[cfg(feature = "std")]
474-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
475471
pub fn std_axis(&self, axis: Axis, ddof: A) -> Array<A, D::Smaller>
476472
where
477473
A: Float + FromPrimitive,

src/partial.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl<T> Partial<T>
3737
}
3838

3939
#[cfg(feature = "rayon")]
40-
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
4140
pub(crate) fn stub() -> Self
4241
{
4342
Self {
@@ -47,7 +46,6 @@ impl<T> Partial<T>
4746
}
4847

4948
#[cfg(feature = "rayon")]
50-
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
5149
pub(crate) fn is_stub(&self) -> bool
5250
{
5351
self.ptr.is_null()
@@ -62,7 +60,6 @@ impl<T> Partial<T>
6260
}
6361

6462
#[cfg(feature = "rayon")]
65-
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
6663
/// Merge if they are in order (left to right) and contiguous.
6764
/// Skips merge if T does not need drop.
6865
pub(crate) fn try_merge(mut left: Self, right: Self) -> Self

0 commit comments

Comments
 (0)