Skip to content

Commit 08f47ce

Browse files
Clarify doc(cfg()) working without cfg() and lift doc(auto_cfg) crate-level only restriction
1 parent cae5f57 commit 08f47ce

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

text/000-rustdoc-cfgs-handling.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This RFC proposes to add the following attributes:
3737

3838
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.
3939

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.
4141

4242
* `#![doc(cfg_hide(...))]` / `#[doc(cfg_show(...))]`
4343

@@ -57,7 +57,9 @@ All of these attributes can be added to a module or to the crate root, and they
5757

5858
### `#[doc(auto_cfg = true)]`/`#[doc(auto_cfg = false)]`
5959

60-
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.
6163

6264
So if we take back the previous example:
6365

@@ -68,7 +70,7 @@ pub mod futures {}
6870

6971
There's no need to "duplicate" the `cfg` into a `doc(cfg())` to make Rustdoc display it.
7072

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.
7274

7375
### `#[doc(cfg(...))]`
7476

@@ -86,6 +88,15 @@ It will display in the documentation for this module:
8688

8789
![This is supported on feature="futures-io" only.](https://user-images.githubusercontent.com/81079/89731116-d7b7ce00-da44-11ea-87c6-022d192d6eca.png)
8890

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+
pub mod futures {}
96+
```
97+
98+
It will be displayed exactly the same as the previous code.
99+
89100
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.
90101

91102
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
268279
# Future possibilities
269280
[future possibilities]: #future-possibilities
270281

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.
272282

273283
## Boolean simplification
274284
[boolean simplification]: #boolean-simplification

0 commit comments

Comments
 (0)