From 37d78b9d7baee351f5f851d6f589f1553736eedc Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 9 Jun 2025 18:11:08 -0700 Subject: [PATCH 1/3] Unwrap automatically_derived --- src/attributes/derive.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/attributes/derive.md b/src/attributes/derive.md index c38bf19c7a..0c05a9c2b0 100644 --- a/src/attributes/derive.md +++ b/src/attributes/derive.md @@ -66,10 +66,7 @@ During macro expansion, for each element in the list of derives, the correspondi r[attributes.derive.automatically_derived] ## The `automatically_derived` attribute -The *`automatically_derived` attribute* is automatically added to -[implementations] created by the `derive` attribute for built-in traits. It -has no direct effect, but it may be used by tools and diagnostic lints to -detect these automatically generated implementations. +The *`automatically_derived` attribute* is automatically added to [implementations] created by the `derive` attribute for built-in traits. It has no direct effect, but it may be used by tools and diagnostic lints to detect these automatically generated implementations. [items]: ../items.md [derive macros]: ../procedural-macros.md#derive-macros From 2895a396dde9ec82999a5c1a121055c549a992ec Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 9 Jun 2025 18:23:49 -0700 Subject: [PATCH 2/3] Convert automatically_derive to use the attribute template --- src/attributes/derive.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/attributes/derive.md b/src/attributes/derive.md index 0c05a9c2b0..518f5fe961 100644 --- a/src/attributes/derive.md +++ b/src/attributes/derive.md @@ -66,10 +66,42 @@ During macro expansion, for each element in the list of derives, the correspondi r[attributes.derive.automatically_derived] ## The `automatically_derived` attribute -The *`automatically_derived` attribute* is automatically added to [implementations] created by the `derive` attribute for built-in traits. It has no direct effect, but it may be used by tools and diagnostic lints to detect these automatically generated implementations. +r[attributes.derive.automatically_derived.intro] +The *`automatically_derived` [attribute][attributes]* is used to annotate an [implementation] to indicate that it was automatically created by a `derive` attribute. It has no direct effect, but it may be used by tools and diagnostic lints to detect these automatically generated implementations. + +> [!EXAMPLE] +> The following is an example of what the [`Clone`] derive may generate for a struct named `Example`. +> ```rust +> # struct Example; +> #[automatically_derived] +> impl ::core::clone::Clone for Example { +> #[inline] +> fn clone(&self) -> Example { +> Example +> } +> } +> ``` + +r[attributes.derive.automatically_derived.syntax] +The `automatically_derived` attribute uses the [MetaWord] syntax and thus does not take any inputs. + +r[attributes.derive.automatically_derived.allowed-positions] +The `automatically_derived` attribute may be placed on an [implementation]. + +> [!NOTE] +> `rustc` currently warns in other positions. + +r[attributes.derive.automatically_derived.duplicates] +Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect. + +> [!NOTE] +> `rustc` currently warns on subsequent duplicate `automatically_derived` attributes. + +r[attributes.derive.automatically_derived.behavior] +The `automatically_derived` attribute has no behavior. [items]: ../items.md [derive macros]: ../procedural-macros.md#derive-macros -[implementations]: ../items/implementations.md +[implementation]: ../items/implementations.md [items]: ../items.md [procedural macros]: ../procedural-macros.md#derive-macros From affd3bfc13e1770911d511d2b1ddbba6d62ca7d0 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Sat, 2 Aug 2025 23:07:35 +0000 Subject: [PATCH 3/3] Revise editorially --- src/attributes/derive.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/attributes/derive.md b/src/attributes/derive.md index 518f5fe961..d65431bc01 100644 --- a/src/attributes/derive.md +++ b/src/attributes/derive.md @@ -67,40 +67,42 @@ r[attributes.derive.automatically_derived] ## The `automatically_derived` attribute r[attributes.derive.automatically_derived.intro] -The *`automatically_derived` [attribute][attributes]* is used to annotate an [implementation] to indicate that it was automatically created by a `derive` attribute. It has no direct effect, but it may be used by tools and diagnostic lints to detect these automatically generated implementations. +The *`automatically_derived` [attribute][attributes]* is used to annotate an [implementation] to indicate that it was automatically created by a [derive macro]. It has no direct effect, but it may be used by tools and diagnostic lints to detect these automatically generated implementations. > [!EXAMPLE] -> The following is an example of what the [`Clone`] derive may generate for a struct named `Example`. +> Given [`#[derive(Clone)]`][macro@Clone] on `struct Example`, the [derive macro] may produce: +> > ```rust > # struct Example; > #[automatically_derived] > impl ::core::clone::Clone for Example { > #[inline] -> fn clone(&self) -> Example { +> fn clone(&self) -> Self { > Example > } > } > ``` r[attributes.derive.automatically_derived.syntax] -The `automatically_derived` attribute uses the [MetaWord] syntax and thus does not take any inputs. +The `automatically_derived` attribute uses the [MetaWord] syntax and so does not accept any arguments. r[attributes.derive.automatically_derived.allowed-positions] The `automatically_derived` attribute may be placed on an [implementation]. > [!NOTE] -> `rustc` currently warns in other positions. +> `rustc` currently accepts the attribute in other positions but lints against it. r[attributes.derive.automatically_derived.duplicates] Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect. > [!NOTE] -> `rustc` currently warns on subsequent duplicate `automatically_derived` attributes. +> `rustc` lints against duplicate use of this attribute. r[attributes.derive.automatically_derived.behavior] The `automatically_derived` attribute has no behavior. [items]: ../items.md +[derive macro]: macro.proc.derive [derive macros]: ../procedural-macros.md#derive-macros [implementation]: ../items/implementations.md [items]: ../items.md