Skip to content

Commit cae5f57

Browse files
Improve auto_cfg attribute syntax and remove doc(cfg()) restriction about not being able to be used at crate-level
1 parent 3978a1c commit cae5f57

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

text/000-rustdoc-cfgs-handling.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ The end goal being to provide this information automatically so that the documen
2929

3030
This RFC proposes to add the following attributes:
3131

32-
* `#![doc(auto_cfg(enable))]`/`#[doc(auto_cfg(disable))]`
32+
* `#![doc(auto_cfg = true)]`/`#[doc(auto_cfg = false)]`
3333

34-
When this is turned on, `#[cfg]` attributes are shown in documentation just like `#[doc(cfg)]` attributes are. By default, `auto_cfg` will be enabled.
34+
When this is turned on (with `doc(auto_cfg = true)`, `#[cfg]` attributes are shown in documentation just like `#[doc(cfg)]` attributes are. By default, `auto_cfg` will be enabled.
3535

3636
* `#[doc(cfg(...))]`
3737

@@ -48,15 +48,14 @@ This RFC proposes to add the following attributes:
4848
[cfg attribute]: https://doc.rust-lang.org/reference/conditional-compilation.html
4949
[`windows` crate]: https://docs.rs/windows/latest/windows/
5050

51-
All of these attributes can be added to a module or to the crate root, and they will be inherited by the child items unless another attribute overrides it (except that `doc(cfg)` cannot be added to the crate root). This is why "opposite" attributes like `cfg_hide` and `cfg_show` are provided: they allow a child item to override its parent.
52-
51+
All of these attributes can be added to a module or to the crate root, and they will be inherited by the child items unless another attribute overrides it. This is why "opposite" attributes like `cfg_hide` and `cfg_show` are provided: they allow a child item to override its parent.
5352

5453
# Reference-level explanation
5554
[reference-level-explanation]: #reference-level-explanation
5655

5756
## The attributes
5857

59-
### `#[doc(auto_cfg(enable))]`/`#[doc(auto_cfg(disable))]`
58+
### `#[doc(auto_cfg = true)]`/`#[doc(auto_cfg = false)]`
6059

6160
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.
6261

@@ -89,11 +88,11 @@ It will display in the documentation for this module:
8988

9089
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.
9190

92-
This attribute works on modules and on items but cannot be used at the crate root level.
91+
This attribute works on modules and on items.
9392

9493
### `#[doc(cfg_hide(...))]`
9594

96-
This attribute is used to prevent some `cfg` to be generated in the visual markers. It only applies to `#[doc(auto_cfg(enable))]`, not to `#[doc(cfg(...))]`. So in the previous example:
95+
This attribute is used to prevent some `cfg` to be generated in the visual markers. It only applies to `#[doc(auto_cfg = true)]`, not to `#[doc(cfg(...))]`. So in the previous example:
9796

9897
```rust
9998
#[cfg(any(unix, feature = "futures-io"))]
@@ -144,7 +143,7 @@ pub fn foo() {}
144143
### `#[doc(cfg_show(...))]`
145144

146145
This attribute does the opposite of `#[doc(cfg_hide(...))]`: if you used `#[doc(cfg_hide(...))]` and want to revert its effect on an item and its descendants, you can use `#[doc(cfg_show(...))]`.
147-
It only applies to `#[doc(auto_cfg(enable))]`, not to `#[doc(cfg(...))]`.
146+
It only applies to `#[doc(auto_cfg = true)]`, not to `#[doc(cfg(...))]`.
148147

149148
For example:
150149

@@ -269,7 +268,7 @@ When re-exporting items with different cfgs there are two things that can happen
269268
# Future possibilities
270269
[future possibilities]: #future-possibilities
271270

272-
The `#[cfg(cfg_auto(enable))]`/`#[cfg(cfg_auto(disable))]` 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.
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.
273272

274273
## Boolean simplification
275274
[boolean simplification]: #boolean-simplification

0 commit comments

Comments
 (0)