From cebfe8137f56bceba1551b9c1d111563eb0d14b2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 5 Mar 2023 14:38:18 -0800 Subject: [PATCH] Update for stable cfg(doc) --- readonly-fields/README.md | 20 ++++++-------------- readonly-fields/demo/.cargo/config.toml | 2 -- readonly-fields/demo/main.rs | 4 ++-- 3 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 readonly-fields/demo/.cargo/config.toml diff --git a/readonly-fields/README.md b/readonly-fields/README.md index 3659c43..c990dc9 100644 --- a/readonly-fields/README.md +++ b/readonly-fields/README.md @@ -207,26 +207,18 @@ field were declared `pub`. ### Third attempt -We can use `#[cfg(rustdoc)]` to distinguish when documentation is being -rendered, though this cfg is currently available on nightly only. The tracking -issue is [rust-lang/rust#43781]. +We can use [`#[cfg(doc)]`][cfgdoc] to distinguish when documentation is being +rendered, which is available since Rust 1.41. -[rust-lang/rust#43781]: https://github.com/rust-lang/rust/issues/43781 - -I ended up using a Cargo config to have rustdoc pass some different cfg. - -```toml -[build] -rustdocflags = ["--cfg", "oqueue_docs"] -``` +[cfgdoc]: https://doc.rust-lang.org/1.67.0/rustdoc/advanced-features.html#cfgdoc-documenting-platform-specific-or-feature-specific-information ```rust #[repr(C)] pub struct Task { - #[cfg(oqueue_docs)] + #[cfg(doc)] pub index: usize, - #[cfg(not(oqueue_docs))] + #[cfg(not(doc))] index: usize, // other private fields @@ -273,7 +265,7 @@ the behavior as an attribute macro][readonly] is the easy part: ```rust /// ... -#[readonly::make(doc = oqueue_docs)] +#[readonly::make] pub struct Task { /// ... /// diff --git a/readonly-fields/demo/.cargo/config.toml b/readonly-fields/demo/.cargo/config.toml deleted file mode 100644 index 60ad800..0000000 --- a/readonly-fields/demo/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -rustdocflags = ["--cfg", "oqueue_docs"] diff --git a/readonly-fields/demo/main.rs b/readonly-fields/demo/main.rs index 28b7db6..b6265f5 100644 --- a/readonly-fields/demo/main.rs +++ b/readonly-fields/demo/main.rs @@ -6,10 +6,10 @@ mod oqueue { #[derive(Default)] #[repr(C)] pub struct Task { - #[cfg(oqueue_docs)] + #[cfg(doc)] pub index: usize, - #[cfg(not(oqueue_docs))] + #[cfg(not(doc))] index: usize, // Other private fields: