Skip to content

Commit e5338b6

Browse files
Change behaviour in case doc(auto_cfg = ...) and doc(auto_cfg(...)) are used on the same attribute
1 parent a295af1 commit e5338b6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

text/000-rustdoc-cfgs-handling.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,29 @@ Using this attribute will re-enable `auto_cfg` if it was disabled at this locati
173173

174174
```rust
175175
#[doc(auto_cfg = false)] // Disabling `auto_cfg`
176-
#[doc(auto_cfg(hide(unix)))] // `auto_cfg` is re-enabled.
177176
pub fn foo() {}
178177
```
179178

179+
And using `doc(auto_cfg)` will re-enable it:
180+
181+
```rust
182+
#[doc(auto_cfg = false)] // Disabling `auto_cfg`
183+
pub mod module {
184+
#[doc(auto_cfg(hide(unix)))] // `auto_cfg` is re-enabled.
185+
pub fn foo() {}
186+
}
187+
```
188+
189+
However, using `doc(auto_cfg = ...)` and `doc(auto_cfg(...))` on the same item will emit an error:
190+
191+
```rust
192+
#[doc(auto_cfg = false)]
193+
#[doc(auto_cfg(hide(unix)))] // error
194+
pub fn foo() {}
195+
```
196+
197+
The reason behind this is that `doc(auto_cfg = ...)` enables or disables the feature, whereas `doc(auto_cfg(...))` enables it unconditionally, making the first attribute to appear useless as it will be overidden by the next `doc(auto_cfg)` attribute.
198+
180199
### `#[doc(auto_cfg(show(...)))]`
181200

182201
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(...)))]`.

0 commit comments

Comments
 (0)