From 424d2426b0a8c879f9f9bfe32c99064f18f27bf6 Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 05:26:13 +0100 Subject: [PATCH 1/5] Attribute documentation for cfg_attr --- library/core/src/attribute_docs.rs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index 97629be8ec6ef..ead2efbcf17c6 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -707,3 +707,50 @@ 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 +/// // 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 +const _: () = (); From 63a9c85be6a73c6f4d3b4b8668172d2beb4fd8b2 Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 05:52:36 +0100 Subject: [PATCH 2/5] 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 ead2efbcf17c6..c5f7f80d7e1c5 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -751,6 +751,6 @@ const _: () = (); /// /// 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 const _: () = (); From 1e418da6e6e04e21d020d5dbef0037d628d69029 Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Mon, 3 Aug 2026 08:28:44 +0100 Subject: [PATCH 3/5] fix merge conflict --- 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 c5f7f80d7e1c5..c2eb34ffa8bcb 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -751,6 +751,6 @@ const _: () = (); /// /// 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 const _: () = (); From 1850727e71e76b703665c5c0c6aebc554bf8a67b Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Wed, 30 Sep 2026 09:00:09 +0100 Subject: [PATCH 4/5] fix ci Signed-off-by: Emmanuel Ugwu --- 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 c2eb34ffa8bcb..a96c7a1388bd1 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -742,7 +742,7 @@ const _: () = (); /// ```rust /// #[cfg_attr( /// all(feature = "system", feature = "disk"), -/// doc = "For module documentation, both `system`, and `disk` need to be enabled.". +/// doc = "For module documentation, both `system`, and `disk` need to be enabled.", /// )] /// mod my_module { /// // ... From 57be633d8ec117a312aed9183353a64cee7e522c Mon Sep 17 00:00:00 2001 From: Emmanuel Ugwu Date: Wed, 30 Sep 2026 12:37:56 +0100 Subject: [PATCH 5/5] address feedback Signed-off-by: Emmanuel Ugwu --- library/core/src/attribute_docs.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/library/core/src/attribute_docs.rs b/library/core/src/attribute_docs.rs index a96c7a1388bd1..9a70ea74345be 100644 --- a/library/core/src/attribute_docs.rs +++ b/library/core/src/attribute_docs.rs @@ -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 _: () = (); @@ -715,11 +715,9 @@ const _: () = (); /// Example: /// /// ```rust -/// // This function is annotated with `#[test]` only on Linux platforms. -/// #[cfg_attr(target_os = "linux", test)] -/// fn my_function() { -/// // ... -/// } +/// // 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: @@ -742,7 +740,7 @@ const _: () = (); /// ```rust /// #[cfg_attr( /// all(feature = "system", feature = "disk"), -/// doc = "For module documentation, both `system`, and `disk` need to be enabled.", +/// doc = "These docs only show up if both `system`, and `disk` are enabled.", /// )] /// mod my_module { /// // ...