Skip to content

Commit 0d7a7b5

Browse files
QuietMisdreavusGuillaumeGomez
authored andcommitted
move cfg(doc) docs into a separate page
1 parent a056bf9 commit 0d7a7b5

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

src/doc/rustdoc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
- [Documentation tests](documentation-tests.md)
88
- [Lints](lints.md)
99
- [Passes](passes.md)
10+
- [Advanced Features](advanced-features.md)
1011
- [Unstable features](unstable-features.md)
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Advanced Features
2+
3+
The features listed on this page fall outside the rest of the main categories.
4+
5+
## `#[cfg(doc)]`: Documenting platform-/feature-specific information
6+
7+
For conditional compilation, Rustdoc treats your crate the same way the compiler does: Only things
8+
from the host target are available (or from the given `--target` if present), and everything else is
9+
"filtered out" from the crate. This can cause problems if your crate is providing different things
10+
on different targets and you want your documentation to reflect all the available items you
11+
provide.
12+
13+
If you want to make sure an item is seen by Rustdoc regardless of what platform it's targeting,
14+
you can apply `#[cfg(doc)]` to it. Rustdoc sets this whenever it's building documentation, so
15+
anything that uses that flag will make it into documentation it generates. To apply this to an item
16+
with other `#[cfg]` filters on it, you can write something like `#[cfg(any(windows, doc))]`.
17+
This will preserve the item either when built normally on Windows, or when being documented
18+
anywhere.
19+
20+
Please note that this feature is not passed to doctests.
21+
22+
Example:
23+
24+
```rust
25+
/// Token struct that can only be used on Windows.
26+
#[cfg(any(windows, doc))]
27+
pub struct WindowsToken;
28+
/// Token struct that can only be used on Unix.
29+
#[cfg(any(unix, doc))]
30+
pub struct UnixToken;
31+
```
32+
33+
Here, the respective tokens can only be used by dependent crates on their respective platforms, but
34+
they will both appear in documentation.

src/doc/rustdoc/src/the-doc-attribute.md

-31
Original file line numberDiff line numberDiff line change
@@ -214,34 +214,3 @@ the `strip-hidden` pass is removed.
214214
Since primitive types are defined in the compiler, there's no place to attach documentation
215215
attributes. This attribute is used by the standard library to provide a way to generate
216216
documentation for primitive types.
217-
218-
## `#[cfg(doc)]`: Documenting platform-/feature-specific information
219-
220-
For conditional compilation, Rustdoc treats your crate the same way the compiler does: Only things
221-
from the host target are available (or from the given `--target` if present), and everything else is
222-
"filtered out" from the crate. This can cause problems if your crate is providing different things
223-
on different targets and you want your documentation to reflect all the available items you
224-
provide.
225-
226-
If you want to make sure an item is seen by Rustdoc regardless of what platform it's targeting,
227-
you can apply `#[cfg(doc)]` to it. Rustdoc sets this whenever it's building documentation, so
228-
anything that uses that flag will make it into documentation it generates. To apply this to an item
229-
with other `#[cfg]` filters on it, you can write something like `#[cfg(any(windows, doc))]`.
230-
This will preserve the item either when built normally on Windows, or when being documented
231-
anywhere.
232-
233-
Please note that this feature won't be passed when building doctests.
234-
235-
Example:
236-
237-
```rust
238-
/// Token struct that can only be used on Windows.
239-
#[cfg(any(windows, doc))]
240-
pub struct WindowsToken;
241-
/// Token struct that can only be used on Unix.
242-
#[cfg(any(unix, doc))]
243-
pub struct UnixToken;
244-
```
245-
246-
Here, the respective tokens can only be used by dependent crates on their respective platforms, but
247-
they will both appear in documentation.

0 commit comments

Comments
 (0)