Skip to content

Commit d855fd3

Browse files
committed
Convert automatically_derive to use the attribute template
1 parent 113deb1 commit d855fd3

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/attributes/derive.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,43 @@ You can implement `derive` for your own traits through [procedural macros].
3838
r[attributes.derive.automatically_derived]
3939
## The `automatically_derived` attribute
4040

41-
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.
41+
r[attributes.derive.automatically_derived.intro]
42+
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.
43+
44+
> [!EXAMPLE]
45+
> The following is an example of what the [`Clone`] derive may generate for a struct named `Example`.
46+
> ```rust
47+
> # struct Example;
48+
> #[automatically_derived]
49+
> impl ::core::clone::Clone for Example {
50+
> #[inline]
51+
> fn clone(&self) -> Example {
52+
> Example
53+
> }
54+
> }
55+
> ```
56+
57+
r[attributes.derive.automatically_derived.syntax]
58+
The `automatically_derived` attribute uses the [MetaWord] syntax and thus does not take any inputs.
59+
60+
r[attributes.derive.automatically_derived.allowed-positions]
61+
The `automatically_derived` attribute may be placed on an [implementation].
62+
63+
> [!NOTE]
64+
> `rustc` currently warns in other positions.
65+
66+
r[attributes.derive.automatically_derived.duplicates]
67+
Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect.
68+
69+
> [!NOTE]
70+
> `rustc` currently warns on subsequent duplicate `automatically_derived` attributes.
71+
72+
r[attributes.derive.automatically_derived.behavior]
73+
The `automatically_derived` attribute has no behavior.
4274
4375
[`impl` item]: ../items/implementations.md
4476
[items]: ../items.md
4577
[derive macros]: ../procedural-macros.md#derive-macros
46-
[implementations]: ../items/implementations.md
78+
[implementation]: ../items/implementations.md
4779
[items]: ../items.md
4880
[procedural macros]: ../procedural-macros.md#derive-macros

0 commit comments

Comments
 (0)