Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion library/core/src/attribute_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const _: () = ();
///
/// For more information, see the Reference on [the `cfg` attribute].
///
/// [`cfg_attr`]: ../reference/conditional-compilation.html#the-cfg_attr-attribute
/// [`cfg_attr`]: ./attribute.cfg_attr.html
/// [the `cfg` attribute]: ../reference/conditional-compilation.html#the-cfg-attribute
/// [`if`]: ./keyword.if.html
const _: () = ();
Expand Down Expand Up @@ -707,3 +707,48 @@ const _: () = ();
/// [Clippy]: https://github.com/rust-lang/rust-clippy
/// [the `automatically_derived` attribute]: ../reference/attributes/derive.html#the-automatically_derived-attribute
const _: () = ();

#[doc(attribute = "cfg_attr")]
//
/// The `cfg_attr` attribute is used to conditionally apply one or more attributes to an item.
///
/// Example:
///
/// ```rust
/// // The struct derives `Debug` when the `debug_impls` feature is enabled.
/// #[cfg_attr(feature = "debug_impls", derive(Debug))]
/// struct X;
/// ```
///
/// You can apply multiple attributes by separating them with commas:
///
/// ```rust
/// #[cfg_attr(feature = "nightly", allow(dead_code), deny(unused_variables))]
/// // This function only gets the `allow(dead_code)` and `deny(unused_variables)` attributes when
/// // `feature = "nightly"` is active.
/// fn nightly_only_function() {
/// let x = 42;
/// }
/// ```
///
/// For complex conditions, you can combine `all(...)`, `any(...)`, and `not(...)`.
///
/// * `all`: True if all given predicates are true.
/// * `any`: True if at least one of the given predicates is true.
/// * `not`: True if the predicate is false.
///
/// ```rust
/// #[cfg_attr(
/// all(feature = "system", feature = "disk"),
/// doc = "These docs only show up if both `system`, and `disk` are enabled.",
/// )]
/// mod my_module {
/// // ...
/// }
/// ```
///
/// For more information, see the Reference on [the `cfg_attr` attribute].
///
/// [`cfg`]: ./attribute.cfg.html
/// [the `cfg_attr` attribute]: ../reference/conditional-compilation.html#the-cfg_attr-attribute
const _: () = ();
Loading