From f1b1fdecda52e48bafbc43409eb0902639e701a2 Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 05:26:13 +0100 Subject: [PATCH 1/4] Attribute documentation for cfg_attr --- library/core/src/attribute_docs.rs | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index b30c449104ad5..96c4e45776cee 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -633,3 +633,51 @@ mod link_section_attribute {} /// /// [the `non_exhaustive` attribute]: ../reference/attributes/type_system.html#the-non_exhaustive-attribute mod non_exhaustive_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 {} + From 198ca6256c3391a1cd81b90bbc80e54fed5859a1 Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 05:52:36 +0100 Subject: [PATCH 2/4] fix CI failure --- library/core/src/attribute_docs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index 96c4e45776cee..cd75f93774237 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -677,7 +677,7 @@ mod non_exhaustive_attribute {} /// /// For more information, see the Reference on [the `cfg_attr` attribute]. /// -/// [the `cfg` attribute]: ../reference/conditional-compilation.html#the-cfg-attribute +/// [the `cfg` attribute]: ./attribute.cfg.html /// [the `cfg_attr` attribute]: ../reference/conditional-compilation.html#the-cfg_attr-attribute mod cfg_attr_attribute {} From f29d29559151c152d495a81da03577dedce35beb Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 08:28:44 +0100 Subject: [PATCH 3/4] fix CI failure --- library/core/src/attribute_docs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index cd75f93774237..21ce6991bf57c 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -677,7 +677,7 @@ mod non_exhaustive_attribute {} /// /// For more information, see the Reference on [the `cfg_attr` attribute]. /// -/// [the `cfg` attribute]: ./attribute.cfg.html +/// [`cfg`]: ./attribute.cfg.html /// [the `cfg_attr` attribute]: ../reference/conditional-compilation.html#the-cfg_attr-attribute mod cfg_attr_attribute {} From 50c1451871ef4ef52569c9d2d679111a239a8b88 Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 17:05:36 +0100 Subject: [PATCH 4/4] fix CI failure --- library/core/src/attribute_docs.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index 21ce6991bf57c..9b0c565c30699 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -680,4 +680,3 @@ mod non_exhaustive_attribute {} /// [`cfg`]: ./attribute.cfg.html /// [the `cfg_attr` attribute]: ../reference/conditional-compilation.html#the-cfg_attr-attribute mod cfg_attr_attribute {} -