Skip to content

Commit 509fdee

Browse files
committed
Revise editorially
Let's be a bit more clear about the purpose of the `derive` attribute being to invoke derive macros, and let's talk about "invoking" these macros rather than "processing" them.
1 parent b9a4f3c commit 509fdee

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/attributes/derive.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ r[attributes.derive]
22
# Derive
33

44
r[attributes.derive.intro]
5-
The *`derive` [attribute][attributes]* allows new [items] to be automatically generated for data structures. You can implement custom `derive` macros through [procedural macros].
5+
The *`derive` [attribute][attributes]* invokes one or more [derive macros], allowing new [items] to be automatically generated for data structures. You can create `derive` macros with [procedural macros].
66

77
> [!EXAMPLE]
8-
> The following example will create an [`impl` item] for the [`PartialEq`] and [`Clone`] traits for `Foo`, and the type parameter `T` will be given the `PartialEq` or `Clone` constraints for the appropriate `impl`:
8+
> The [`PartialEq`][macro@PartialEq] derive macro emits an [implementation] of [`PartialEq`] for `Foo<T> where T: PartialEq`. The [`Clone`][macro@Clone] derive macro does likewise for [`Clone`].
99
>
1010
> ```rust
1111
> #[derive(PartialEq, Clone)]
@@ -15,7 +15,7 @@ The *`derive` [attribute][attributes]* allows new [items] to be automatically ge
1515
> }
1616
> ```
1717
>
18-
> The generated `impl` for `PartialEq` is equivalent to
18+
> The generated `impl` items are equivalent to:
1919
>
2020
> ```rust
2121
> # struct Foo<T> { a: i32, b: T }
@@ -24,16 +24,22 @@ The *`derive` [attribute][attributes]* allows new [items] to be automatically ge
2424
> self.a == other.a && self.b == other.b
2525
> }
2626
> }
27+
>
28+
> impl<T: Clone> Clone for Foo<T> {
29+
> fn clone(&self) -> Self {
30+
> Foo { a: self.a.clone(), b: self.b.clone() }
31+
> }
32+
> }
2733
> ```
2834
2935
r[attributes.derive.syntax]
30-
The `derive` attribute uses the [MetaListPaths] syntax to specify a list of paths to [derive macros] to process.
36+
The `derive` attribute uses the [MetaListPaths] syntax to specify a list of paths to [derive macros] to invoke.
3137
3238
r[attributes.derive.allowed-positions]
3339
The `derive` attribute may be applied to [structs][items.struct], [enums][items.enum], and [unions][items.union].
3440
3541
r[attributes.derive.duplicates]
36-
The `derive` attribute may be specified multiple times on an item, with all entries from all attributes being processed.
42+
The `derive` attribute may be specified multiple times on an item, with all derive macros listed in all attributes being invoked.
3743
3844
r[attributes.derive.stdlib]
3945
The `derive` attribute is exported in the standard library prelude as [`core::prelude::v1::derive`].
@@ -65,9 +71,9 @@ The *`automatically_derived` attribute* is automatically added to
6571
has no direct effect, but it may be used by tools and diagnostic lints to
6672
detect these automatically generated implementations.
6773
68-
[`impl` item]: ../items/implementations.md
6974
[items]: ../items.md
7075
[derive macros]: ../procedural-macros.md#derive-macros
76+
[implemenattion]: ../items/implementations.md
7177
[implementations]: ../items/implementations.md
7278
[items]: ../items.md
7379
[procedural macros]: ../procedural-macros.md#derive-macros

0 commit comments

Comments
 (0)