Skip to content
Open
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: 47 additions & 0 deletions library/core/src/attribute_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,50 @@ mod proc_macro_attribute {}
///
/// [the `link_section` attribute]: ../reference/abi.html#the-link_section-attribute
mod link_section_attribute {}

#[doc(attribute = "cfg_attr")]
//
/// The `cfg_attr` attribute is used to conditionally apply one or more attributes to an item.
///
/// Example:
///
/// ```rust
/// // This function is annotated with `#[test]` only on Linux platforms.
/// #[cfg_attr(target_os = "linux", test)]
/// fn my_function() {
/// // ...
/// }
/// ```
///
/// 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 = "For module documentation, both `system`, and `disk` need to be enabled.",
/// )]
/// mod my_module {
/// // ...
/// }
/// ```
///
/// For more information, see the Reference on [the `cfg_attr` attribute].
///
/// [the `cfg` attribute]: ../reference/conditional-compilation.html#the-cfg-attribute
/// [the `cfg_attr` attribute]: ../reference/conditional-compilation.html#the-cfg_attr-attribute
mod cfg_attr_attribute {}
Loading