Skip to content

Commit 1b43ed5

Browse files
committed
doc: switch from doc_auto_cfg to doc_cfg
In rust-lang/rust#138907, the `doc_auto_cfg` feature was subsumed by `doc_cfg`. This does overall looks like we're on a path toward stabilization, which is great. One problem here though is that a bunch of crates use the `cfg` `docsrs` to enable `doc_auto_cfg`. So if we enable it, then it causes those crates to emit hard errors. This is overall very annoying, and I don't know how to unfuck things. So I changed the `cfg` knob to `docsrs_jiff` which, doesn't quite provide a guarantee, but gets us closer to being masters of our own destiny. See also a similar change made to `regex`: rust-lang/regex#1305
1 parent 877d90a commit 1b43ed5

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,24 @@ jobs:
549549
cd crates/jiff-wasm
550550
wasm-pack test --node
551551
552+
# This job checks the docsrs configuration.
553+
#
554+
# This is important because we enable `doc_cfg`, which is an unstable
555+
# feature that can (and has) broken.
556+
docsrs:
557+
runs-on: ubuntu-latest
558+
env:
559+
RUSTDOCFLAGS: "-D rustdoc::broken_intra_doc_links --cfg docsrs_jiff"
560+
steps:
561+
- name: Checkout repository
562+
uses: actions/checkout@v4
563+
- name: Install Rust
564+
uses: dtolnay/rust-toolchain@master
565+
with:
566+
toolchain: nightly
567+
- name: Build docs
568+
run: cargo doc --verbose --workspace --all-features
569+
552570
# Check that all files are formatted properly.
553571
rustfmt:
554572
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,20 @@ debug-assertions = false
274274
all-features = true
275275
# Since this crate's feature setup is pretty complicated, it is worth opting
276276
# into a nightly unstable option to show the features that need to be enabled
277-
# for public API items. To do that, we set 'docsrs', and when that's enabled,
278-
# we enable the 'doc_auto_cfg' feature.
277+
# for public API items. To do that, we set `docsrs_jiff`, and when that's
278+
# enabled, we enable the 'doc_cfg' feature.
279279
#
280280
# To test this locally, run:
281281
#
282-
# RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features
283-
rustdoc-args = ["--cfg", "docsrs"]
282+
# RUSTDOCFLAGS="--cfg docsrs_jiff" cargo +nightly doc --all-features
283+
#
284+
# Note that we use `docsrs_jiff` instead of the more standard `docsrs` because
285+
# other crates use that same `cfg` knob. And since we are enabling a nightly
286+
# feature, they sometimes break. By using our "own" `cfg` knob, we are closer
287+
# to being masters of our own destiny.
288+
rustdoc-args = ["--cfg", "docsrs_jiff"]
289+
290+
# This squashes the (AFAIK) erroneous warning that `docsrs_jiff` is not a
291+
# valid `cfg` knob.
292+
[lints.rust]
293+
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(docsrs_jiff)'] }

crates/jiff-icu/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,26 @@ icu_time = { version = "2.0.0", optional = true, default-features = false }
4242
[dev-dependencies]
4343
jiff = { version = "0.2.11", path = "../..", default-features = true }
4444
icu = { version = "2.0.0" }
45+
46+
[package.metadata.docs.rs]
47+
# We want to document all features.
48+
all-features = true
49+
# Since this crate's feature setup is pretty complicated, it is worth opting
50+
# into a nightly unstable option to show the features that need to be enabled
51+
# for public API items. To do that, we set `docsrs_jiff`, and when that's
52+
# enabled, we enable the 'doc_cfg' feature.
53+
#
54+
# To test this locally, run:
55+
#
56+
# RUSTDOCFLAGS="--cfg docsrs_jiff" cargo +nightly doc --all-features
57+
#
58+
# Note that we use `docsrs_jiff` instead of the more standard `docsrs` because
59+
# other crates use that same `cfg` knob. And since we are enabling a nightly
60+
# feature, they sometimes break. By using our "own" `cfg` knob, we are closer
61+
# to being masters of our own destiny.
62+
rustdoc-args = ["--cfg", "docsrs_jiff"]
63+
64+
# This squashes the (AFAIK) erroneous warning that `docsrs_jiff` is not a
65+
# valid `cfg` knob.
66+
[lints.rust]
67+
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(docsrs_jiff)'] }

crates/jiff-icu/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ assert_eq!(zdt.to_string(), "2025-02-02T17:30:00-05:00[America/New_York]");
152152

153153
#![no_std]
154154
#![deny(missing_docs)]
155+
// This adds Cargo feature annotations to items in the rustdoc output. Which is
156+
// sadly hugely beneficial for this crate due to the number of features.
157+
#![cfg_attr(docsrs_jiff, feature(doc_cfg))]
155158

156159
#[cfg(any(test, feature = "std"))]
157160
extern crate std;

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,9 @@ For more, see the [`fmt::serde`] sub-module. (This requires enabling Jiff's
720720
)),
721721
allow(dead_code, unused_imports)
722722
)]
723-
// No clue why this thing is still unstable because it's pretty amazing. This
724-
// adds Cargo feature annotations to items in the rustdoc output. Which is
723+
// This adds Cargo feature annotations to items in the rustdoc output. Which is
725724
// sadly hugely beneficial for this crate due to the number of features.
726-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
725+
#![cfg_attr(docsrs_jiff, feature(doc_cfg))]
727726
// We generally want all types to impl Debug.
728727
#![warn(missing_debug_implementations)]
729728
// Document ALL THE THINGS!

0 commit comments

Comments
 (0)