@@ -214,3 +214,34 @@ the `strip-hidden` pass is removed.
214214Since primitive types are defined in the compiler, there's no place to attach documentation
215215attributes. This attribute is used by the standard library to provide a way to generate
216216documentation for primitive types.
217+
218+ ## ` #[cfg(rustdoc)] ` : 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(rustdoc)] ` 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, rustdoc))] ` .
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, rustdoc))]
240+ pub struct WindowsToken ;
241+ /// Token struct that can only be used on Unix.
242+ #[cfg(any(unix, rustdoc))]
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