Skip to content

Commit d7e496f

Browse files
feature(doc_cfg): add docs for cfg(rustdoc)
1 parent 1a3bb27 commit d7e496f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/doc/rustdoc/src/unstable-features.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,25 @@ The `#[doc(cfg(...))]` attribute has another effect: When Rustdoc renders docume
106106
item, it will be accompanied by a banner explaining that the item is only available on certain
107107
platforms.
108108

109-
As mentioned earlier, getting the items to Rustdoc requires some extra preparation. The standard
110-
library adds a `--cfg dox` flag to every Rustdoc command, but the same thing can be accomplished by
111-
adding a feature to your Cargo.toml and adding `--feature dox` (or whatever you choose to name the
112-
feature) to your `cargo doc` calls.
109+
For Rustdoc to document an item, it needs to see it, regardless of what platform it's currently
110+
running on. To aid this, Rustdoc sets the flag `#[cfg(rustdoc)]` when running on your crate.
111+
Combining this with the target platform of a given item allows it to appear when building your crate
112+
normally on that platform, as well as when building documentation anywhere.
113113

114-
Either way, once you create an environment for the documentation, you can start to augment your
115-
`#[cfg]` attributes to allow both the target platform *and* the documentation configuration to leave
116-
the item in. For example, `#[cfg(any(windows, feature = "dox"))]` will preserve the item either on
117-
Windows or during the documentation process. Then, adding a new attribute `#[doc(cfg(windows))]`
118-
will tell Rustdoc that the item is supposed to be used on Windows. For example:
114+
For example, `#[cfg(any(windows, rustdoc))]` will preserve the item either on Windows or during the
115+
documentation process. Then, adding a new attribute `#[doc(cfg(windows))]` will tell Rustdoc that
116+
the item is supposed to be used on Windows. For example:
119117

120118
```rust
121119
#![feature(doc_cfg)]
122120

123121
/// Token struct that can only be used on Windows.
124-
#[cfg(any(windows, feature = "dox"))]
122+
#[cfg(any(windows, rustdoc))]
125123
#[doc(cfg(windows))]
126124
pub struct WindowsToken;
127125

128126
/// Token struct that can only be used on Unix.
129-
#[cfg(any(unix, feature = "dox"))]
127+
#[cfg(any(unix, rustdoc))]
130128
#[doc(cfg(unix))]
131129
pub struct UnixToken;
132130
```

src/doc/unstable-book/src/language-features/doc-cfg.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ This attribute has two effects:
1212

1313
2. The item's doc-tests will only run on the specific platform.
1414

15+
In addition to allowing the use of the `#[doc(cfg)]` attribute, this feature enables the use of a
16+
special conditional compilation flag, `#[cfg(rustdoc)]`, set whenever building documentation on your
17+
crate.
18+
1519
This feature was introduced as part of PR [#43348] to allow the platform-specific parts of the
1620
standard library be documented.
1721

1822
```rust
1923
#![feature(doc_cfg)]
2024

21-
#[cfg(any(windows, feature = "documentation"))]
25+
#[cfg(any(windows, rustdoc))]
2226
#[doc(cfg(windows))]
2327
/// The application's icon in the notification area (a.k.a. system tray).
2428
///
@@ -39,4 +43,4 @@ pub struct Icon {
3943
```
4044

4145
[#43781]: https://github.com/rust-lang/rust/issues/43781
42-
[#43348]: https://github.com/rust-lang/rust/issues/43348
46+
[#43348]: https://github.com/rust-lang/rust/issues/43348

0 commit comments

Comments
 (0)