Skip to content

Commit f350c4f

Browse files
Explain how doc(cfg) and doc(auto_cfg) interacts
1 parent 4746afc commit f350c4f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

text/000-rustdoc-cfgs-handling.md

+13
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ pub mod desktop {
227227
228228
[Future versions of rustdoc][boolean simplification] may simplify this display down to "available on **Windows** only."
229229

230+
## `doc(cfg)` and `doc(auto_cfg)` used on a same item
231+
232+
If `doc(cfg)` is used on an item while `doc(auto_cfg)` is enabled, both will be merged:
233+
234+
```rust
235+
// `doc(auto_cfg)` is enabled here
236+
#[doc(cfg(feature = "futures-io"))]
237+
#[cfg(feature = "something")]
238+
pub mod futures {}
239+
```
240+
241+
In this case, it'll display that both `feature = "futures-io"` and `feature = "something"` are required to use this module. Just like lints, users will get better control over this feature. For example if someone wants to completely override doc cfg attributes on a given item, they will be able to disable it for this item completely and then add what they want using `doc(cfg)`. An example for this is in case you have "parent" features with a lot of children and want to simplify some children `cfg` display when rendered in documentation.
242+
230243
### Re-exports and inlining
231244

232245
`cfg` attributes of a re-export are never merged with the re-exported item(s) attributes except if the re-export has the `#[doc(inline)]` attribute. In this case, the `cfg` of the re-exported item will be merged with the re-export's.

0 commit comments

Comments
 (0)