From 69634b700e31b00069b4d010957aff57db6e69aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 18 Jan 2021 01:00:23 +0300 Subject: [PATCH 1/3] Use doc_cfg to improve register_custom_getrandom docs --- Cargo.toml | 1 + src/custom.rs | 3 +-- src/lib.rs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ddc04776a..b655287a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,4 @@ test-in-browser = [] [package.metadata.docs.rs] features = ["std", "custom"] +rustdoc-args = ["--cfg", "docsrs"] diff --git a/src/custom.rs b/src/custom.rs index 7184e0e22..0d3123c58 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -12,8 +12,6 @@ use core::num::NonZeroU32; /// Register a function to be invoked by `getrandom` on unsupported targets. /// -/// *This API requires the `"custom"` Cargo feature to be activated*. -/// /// ## Writing a custom `getrandom` implementation /// /// The function to register must have the same signature as @@ -75,6 +73,7 @@ use core::num::NonZeroU32; /// [top-level documentation](index.html#custom-implementations) this /// registration only has an effect on unsupported targets. #[macro_export] +#[cfg_attr(docsrs, doc(cfg(feature = "custom")))] macro_rules! register_custom_getrandom { ($path:path) => { // We use an extern "C" function to get the guarantees of a stable ABI. diff --git a/src/lib.rs b/src/lib.rs index 4b19e1666..c3145777b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -146,6 +146,7 @@ )] #![no_std] #![warn(rust_2018_idioms, unused_lifetimes, missing_docs)] +#![cfg_attr(docsrs, feature(doc_cfg))] #[macro_use] extern crate cfg_if; From 2cfbd8ee60d05e26c90505554c8bdf929ab7116a Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 19 Jan 2021 02:46:38 -0800 Subject: [PATCH 2/3] Modify doc tests to set `docsrs` Signed-off-by: Joe Richey --- .github/workflows/tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f7d284157..3b56a943a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly # Needed for -Z minimal-versions + toolchain: nightly # Needed for -Z minimal-versions and doc_cfg override: true - uses: Swatinem/rust-cache@v1 - name: Install precompiled cargo-deadlinks @@ -30,7 +30,10 @@ jobs: wget -O /tmp/cargo-deadlinks $URL chmod +x /tmp/cargo-deadlinks mv /tmp/cargo-deadlinks ~/.cargo/bin - - run: cargo deadlinks -- --features=custom,std + - name: Generate Docs + env: + RUSTDOCFLAGS: --cfg docsrs + run: cargo deadlinks -- --features=custom,std - run: | cargo generate-lockfile -Z minimal-versions cargo test --features=custom,std From d7a0d580d450e1591b95c629043c7c13c383cc76 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Tue, 19 Jan 2021 02:46:59 -0800 Subject: [PATCH 3/3] Set doc(cfg(feature = "std")) on std trait impls Signed-off-by: Joe Richey --- src/error_impls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/error_impls.rs b/src/error_impls.rs index 5cb88405f..61f46d227 100644 --- a/src/error_impls.rs +++ b/src/error_impls.rs @@ -5,6 +5,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg_attr(docsrs, doc(cfg(feature = "std")))] extern crate std; use crate::Error;