You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/000-rustdoc-cfgs-handling.md
+14-4Lines changed: 14 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ This RFC proposes to add the following attributes:
37
37
38
38
This attribute is used to document the operating systems, feature flags, and build profiles where an item is available. For example, `#[doc(cfg(unix))` will add a tag that says "this is supported on **unix** only" to the item.
39
39
40
-
The syntax of this attribute is the same as the syntax of the [`#[cfg(unix)]` attribute][cfg attribute] used for conditional compilation.
40
+
The syntax of this attribute is the same as the syntax of the [`#[cfg()]` attribute][cfg attribute] used for conditional compilation.
This is a crate-level attribute. By default, `#[doc(auto_cfg)]` is enabled at the crate-level. When it's enabled, Rustdoc will automatically display `cfg(...)` compatibility information as-if the same `#[doc(cfg(...))]` had been specified.
60
+
By default, `#[doc(auto_cfg)]` is enabled at the crate-level. When it's enabled, Rustdoc will automatically display `cfg(...)` compatibility information as-if the same `#[doc(cfg(...))]` had been specified.
61
+
62
+
This attribute impacts the item on which it is used and its descendants.
61
63
62
64
So if we take back the previous example:
63
65
@@ -68,7 +70,7 @@ pub mod futures {}
68
70
69
71
There's no need to "duplicate" the `cfg` into a `doc(cfg())` to make Rustdoc display it.
70
72
71
-
In some situations, the detailed conditional compilation rules used to implement the feature might not serve as good documentation (for example, the list of supported platforms might be very long, and it might be better to document them in one place). To turn it off, add the `#[doc(auto_cfg(disable))]` attribute at the crate-level.
73
+
In some situations, the detailed conditional compilation rules used to implement the feature might not serve as good documentation (for example, the list of supported platforms might be very long, and it might be better to document them in one place). To turn it off, add the `#[doc(auto_cfg = false)]` attribute on the item.
72
74
73
75
### `#[doc(cfg(...))]`
74
76
@@ -86,6 +88,15 @@ It will display in the documentation for this module:
86
88
87
89

88
90
91
+
You can use it to display information in generated documentation, whether or not there is a `#[cfg()]` attribute:
92
+
93
+
```rust
94
+
#[doc(cfg(feature ="futures-io"))]
95
+
pubmodfutures {}
96
+
```
97
+
98
+
It will be displayed exactly the same as the previous code.
99
+
89
100
This attribute has the same syntax as conditional compilation, but it only causes documentation to be added. This means `#[doc(cfg(not(windows)))]` will not cause your docs to be hidden on non-windows targets, even though `#[cfg(not(windows))]` does do that.
90
101
91
102
This attribute works on modules and on items.
@@ -268,7 +279,6 @@ When re-exporting items with different cfgs there are two things that can happen
268
279
# Future possibilities
269
280
[future possibilities]: #future-possibilities
270
281
271
-
The `#[cfg(cfg_auto = true)]`/`#[cfg(cfg_auto = false)]` attribute is crate-level only for now as it doesn't really seem useful to be used on a specific item at the moment. However, if needed, this restriction could be lifted in the future if new needs come to appear.
0 commit comments