diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-09-06 10:51:52 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-11-21 15:37:36 +0100 |
| commit | 086c8d3db71c7d448b55536d6862f177ad7f60dd (patch) | |
| tree | a80a5067fe39d49c7b96c999ad97dc27d9338cec /src/doc | |
| parent | f1b882b55805c342e46ee4ca3beeef1d1fa2044b (diff) | |
| download | rust-086c8d3db71c7d448b55536d6862f177ad7f60dd.tar.gz rust-086c8d3db71c7d448b55536d6862f177ad7f60dd.zip | |
Stabilize cfg rustdoc
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/rustdoc/src/the-doc-attribute.md | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/doc/rustdoc/src/the-doc-attribute.md b/src/doc/rustdoc/src/the-doc-attribute.md index 80ac405eb2f..3aaac9268ff 100644 --- a/src/doc/rustdoc/src/the-doc-attribute.md +++ b/src/doc/rustdoc/src/the-doc-attribute.md @@ -214,3 +214,34 @@ the `strip-hidden` pass is removed. Since primitive types are defined in the compiler, there's no place to attach documentation attributes. This attribute is used by the standard library to provide a way to generate documentation for primitive types. + +## `#[cfg(rustdoc)]`: Documenting platform-/feature-specific information + +For conditional compilation, Rustdoc treats your crate the same way the compiler does: Only things +from the host target are available (or from the given `--target` if present), and everything else is +"filtered out" from the crate. This can cause problems if your crate is providing different things +on different targets and you want your documentation to reflect all the available items you +provide. + +If you want to make sure an item is seen by Rustdoc regardless of what platform it's targeting, +you can apply `#[cfg(rustdoc)]` to it. Rustdoc sets this whenever it's building documentation, so +anything that uses that flag will make it into documentation it generates. To apply this to an item +with other `#[cfg]` filters on it, you can write something like `#[cfg(any(windows, rustdoc))]`. +This will preserve the item either when built normally on Windows, or when being documented +anywhere. + +Please note that this feature won't be passed when building doctests. + +Example: + +```rust +/// Token struct that can only be used on Windows. +#[cfg(any(windows, rustdoc))] +pub struct WindowsToken; +/// Token struct that can only be used on Unix. +#[cfg(any(unix, rustdoc))] +pub struct UnixToken; +``` + +Here, the respective tokens can only be used by dependent crates on their respective platforms, but +they will both appear in documentation. |
