Skip to content

Commit 4746afc

Browse files
Allow auto_cfg to take no argument and also make hide and show to re-enable auto_cfg if it was disabled
1 parent aad1fbd commit 4746afc

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

text/000-rustdoc-cfgs-handling.md

Lines changed: 24 additions & 6 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 = true)]`/`#[doc(auto_cfg = false)]`
32+
* `#[doc(auto_cfg)]`/`#[doc(auto_cfg = true)]`/`#[doc(auto_cfg = false)]`
3333

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.
34+
When this is turned on (with `doc(auto_cfg)` or `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

@@ -43,7 +43,7 @@ This RFC proposes to add the following attributes:
4343

4444
These attributes suppress or un-suppress the `auto_cfg` behavior for a particular configuration predicate.
4545

46-
For example, `#[doc(auto_cfg(hide(windows)))]` could be used in newer versions of the [`windows` crate] to prevent the "this is supported on **windows** only" tag from being shown on every single item.
46+
For example, `#[doc(auto_cfg(hide(windows)))]` could be used in newer versions of the [`windows` crate] to prevent the "this is supported on **windows** only" tag from being shown on every single item. Using these attributes will also re-enable `doc(auto_cfg)` if it was disabled at this location.
4747

4848
[cfg attribute]: https://doc.rust-lang.org/reference/conditional-compilation.html
4949
[`windows` crate]: https://docs.rs/windows/latest/windows/
@@ -55,7 +55,7 @@ All of these attributes can be added to a module or to the crate root, and they
5555

5656
## The attributes
5757

58-
### `#[doc(auto_cfg = true)]`/`#[doc(auto_cfg = false)]`
58+
### `#[doc(auto_cfg)`/`#[doc(auto_cfg = true)]`/`#[doc(auto_cfg = false)]`
5959

6060
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.
6161

@@ -72,6 +72,8 @@ There's no need to "duplicate" the `cfg` into a `doc(cfg())` to make Rustdoc dis
7272

7373
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.
7474

75+
If no argument is specified (ie `#[doc(auto_cfg)]`), it's the same as writing `#[doc(auto_cfg = true)]`.
76+
7577
### `#[doc(cfg(...))]`
7678

7779
This attribute provides a standardized format to override `#[cfg()]` attributes to document conditionally available items. Example:
@@ -151,6 +153,14 @@ If `cfg_auto(show(...))` and `cfg_auto(hide(...))` are used to show/hide a same
151153
pub fn foo() {}
152154
```
153155

156+
Using this attribute will re-enable `auto_cfg` if it was disabled at this location:
157+
158+
```rust
159+
#[doc(auto_cfg = false)] // Disabling `auto_cfg`
160+
#[doc(auto_cfg(hide(unix)))] // `auto_cfg` is re-enabled.
161+
pub fn foo() {}
162+
```
163+
154164
### `#[doc(auto_cfg(show(...)))]`
155165

156166
This attribute does the opposite of `#[doc(auto_cfg(hide(...)))]`: if you used `#[doc(auto_cfg(hide(...)))]` and want to revert its effect on an item and its descendants, you can use `#[doc(auto_cfg(show(...)))]`.
@@ -186,8 +196,16 @@ But you cannot write:
186196
If `auto_cfg(show(...))` and `auto_cfg(hide(...))` are used to show/hide a same `cfg` on a same item, it'll emit an error. Example:
187197

188198
```rust
189-
#[doc(auto_cfg(hide(unix)))]
190-
#[doc(auto_cfg(show(unix)))] // Error!
199+
#[doc(auto_cfg(show(unix)))]
200+
#[doc(auto_cfg(hide(unix)))] // Error!
201+
pub fn foo() {}
202+
```
203+
204+
Using this attribute will re-enable `auto_cfg` if it was disabled at this location:
205+
206+
```rust
207+
#[doc(auto_cfg = false)] // Disabling `auto_cfg`
208+
#[doc(auto_cfg(show(unix)))] // `auto_cfg` is re-enabled.
191209
pub fn foo() {}
192210
```
193211

0 commit comments

Comments
 (0)