Skip to content

Commit 241d977

Browse files
committedJan 13, 2022
Update documentation for doc_cfg
1 parent f7bb8e3 commit 241d977

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

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

+33
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@ in documentation.
8484
`#![feature(doc_cfg)]` feature gate. For more information, see [its chapter in the Unstable
8585
Book][unstable-doc-cfg] and [its tracking issue][issue-doc-cfg].
8686

87+
### `doc_auto_cfg`: Automatically generate `#[doc(cfg)]`
88+
89+
`doc_auto_cfg` is an extension to the `#[doc(cfg)]` feature. With it, you don't need to add
90+
`#[doc(cfg(...)]` anymore unless you want to override the default behaviour. So if we take the
91+
previous source code:
92+
93+
```rust
94+
#![feature(doc_auto_cfg)]
95+
96+
/// Token struct that can only be used on Windows.
97+
#[cfg(any(windows, doc))]
98+
pub struct WindowsToken;
99+
100+
/// Token struct that can only be used on Unix.
101+
#[cfg(any(unix, doc))]
102+
pub struct UnixToken;
103+
104+
/// Token struct that is only available with the `serde` feature
105+
#[cfg(feature = "serde")]
106+
#[derive(serde::Deserialize)]
107+
pub struct SerdeToken;
108+
```
109+
110+
It'll render almost the same, the difference being that `doc` will also be displayed. To fix this,
111+
you can use `doc_cfg_hide`:
112+
113+
```rust
114+
#![feature(doc_cfg_hide)]
115+
#![doc(cfg_hide(doc))]
116+
```
117+
118+
And `doc` won't show up anymore!
119+
87120
[cfg-doc]: ./advanced-features.md
88121
[unstable-doc-cfg]: ../unstable-book/language-features/doc-cfg.html
89122
[issue-doc-cfg]: https://github.com/rust-lang/rust/issues/43781

0 commit comments

Comments
 (0)
Please sign in to comment.