Skip to content

Commit aad1fbd

Browse files
Add some explanations on cfged out items
1 parent d2ee5df commit aad1fbd

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
@@ -13,7 +13,7 @@ This RFC aims at providing rustdoc users the possibility to add visual markers t
1313

1414
It does not aim to allow having a same item with different `cfg`s to appear more than once in the generated documentation.
1515

16-
It does not aim to document items which are *inactive* under the current configuration (i.e., “`cfg`'ed out”).
16+
It does not aim to document items which are *inactive* under the current configuration (i.e., “`cfg`ed out”). More details in the [Unresolved questions section](#unresolved-questions).
1717

1818
# Motivation
1919
[motivation]: #motivation
@@ -288,6 +288,25 @@ When re-exporting items with different cfgs there are two things that can happen
288288
# Unresolved questions
289289
[unresolved-questions]: #unresolved-questions
290290

291+
## `cfg`ed out items
292+
293+
Rustdoc doesn't take into account `cfg`ed out items. The reason for this limitation is that Rustdoc has only access to rustc's information: `cfg`ed out items, although still present, don't have enough information to be useful to rustdoc when generating documentation, hence why they are not treated.
294+
295+
So for the following crate, `function` wouldn't show up in the generated docs unless you actually passed `--cfg special` to Rustdoc:
296+
297+
```rust
298+
#[cfg(special)]
299+
pub fn function() {}
300+
```
301+
302+
Therefore, the common and offical workaround is the use of the semi-special cfg `doc`:
303+
304+
```rust
305+
#[cfg(any(doc, special))]
306+
pub fn function() {}
307+
```
308+
309+
There are a few leads on how Rustdoc could solve this issue, but they all come with big drawbacks, so this problem is not addressed in this RFC but will (hopefully) be in the future.
291310

292311
# Future possibilities
293312
[future possibilities]: #future-possibilities

0 commit comments

Comments
 (0)