Skip to content

Commit 0c4439d

Browse files
authored
Merge pull request #1884 from ehuss/automatically_derived
Update `automatically_derived` to use the attribute template
2 parents a2406f5 + affd3bf commit 0c4439d

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/attributes/derive.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,44 @@ During macro expansion, for each element in the list of derives, the correspondi
6666
r[attributes.derive.automatically_derived]
6767
## The `automatically_derived` attribute
6868
69-
The *`automatically_derived` attribute* is automatically added to
70-
[implementations] created by the `derive` attribute for built-in traits. It
71-
has no direct effect, but it may be used by tools and diagnostic lints to
72-
detect these automatically generated implementations.
69+
r[attributes.derive.automatically_derived.intro]
70+
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.
71+
72+
> [!EXAMPLE]
73+
> Given [`#[derive(Clone)]`][macro@Clone] on `struct Example`, the [derive macro] may produce:
74+
>
75+
> ```rust
76+
> # struct Example;
77+
> #[automatically_derived]
78+
> impl ::core::clone::Clone for Example {
79+
> #[inline]
80+
> fn clone(&self) -> Self {
81+
> Example
82+
> }
83+
> }
84+
> ```
85+
86+
r[attributes.derive.automatically_derived.syntax]
87+
The `automatically_derived` attribute uses the [MetaWord] syntax and so does not accept any arguments.
88+
89+
r[attributes.derive.automatically_derived.allowed-positions]
90+
The `automatically_derived` attribute may be placed on an [implementation].
91+
92+
> [!NOTE]
93+
> `rustc` currently accepts the attribute in other positions but lints against it.
94+
95+
r[attributes.derive.automatically_derived.duplicates]
96+
Duplicate instances of the `automatically_derived` attribute on the same implementation have no effect.
97+
98+
> [!NOTE]
99+
> `rustc` lints against duplicate use of this attribute.
100+
101+
r[attributes.derive.automatically_derived.behavior]
102+
The `automatically_derived` attribute has no behavior.
73103
74104
[items]: ../items.md
105+
[derive macro]: macro.proc.derive
75106
[derive macros]: ../procedural-macros.md#derive-macros
76-
[implementations]: ../items/implementations.md
107+
[implementation]: ../items/implementations.md
77108
[items]: ../items.md
78109
[procedural macros]: ../procedural-macros.md#derive-macros

0 commit comments

Comments
 (0)