Skip to content

Commit 68047ac

Browse files
committed
Document the derive macro sub-namespace
1 parent cc1d51c commit 68047ac

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/names/namespaces.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ r[names.namespaces.sub-namespaces]
110110
## Sub-namespaces
111111

112112
r[names.namespaces.sub-namespaces.intro]
113-
The macro namespace is split into two sub-namespaces: one for [bang-style macros] and one for [attributes].
114-
When an attribute is resolved, any bang-style macros in scope will be ignored.
115-
And conversely resolving a bang-style macro will ignore attribute macros in scope.
113+
The macro namespace is split into three sub-namespaces: [bang-style macros], [attributes], and [derives].
114+
When a macro from one sub-namespace is resolved, any macros from other sub-namespaces in scope will be ignored.
116115
This prevents one style from shadowing another.
117116

118117
For example, the [`cfg` attribute] and the [`cfg` macro] are two different entities with the same name in the macro namespace, but they can still be used in their respective context.
@@ -136,6 +135,7 @@ It is still an error for a [`use` import] to shadow another macro, regardless of
136135
[Associated type declarations]: ../items/associated-items.md#associated-types
137136
[Attribute macros]: ../procedural-macros.md#attribute-macros
138137
[attributes]: ../attributes.md
138+
[derives]: ../attributes/derive.md
139139
[bang-style macros]: ../macros.md
140140
[Block labels]: ../expressions/loop-expr.md#labelled-block-expressions
141141
[boolean]: ../types/boolean.md

src/procedural-macros.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ These macros are defined by a [public] [function] with the `proc_macro`
9494
output [`TokenStream`] replaces the entire macro invocation.
9595
9696
r[macro.proc.function.namespace]
97-
The `proc_macro` attribute defines the macro in the [macro namespace] in the root of the crate.
97+
The `proc_macro` attribute defines the macro in the [bang-style sub-namespace][sub-namespace] of the [macro namespace] in the root of the crate.
9898
9999
For example, the following macro definition ignores its input and outputs a
100100
function `answer` into its scope.
@@ -144,7 +144,7 @@ Custom derive macros are defined by a [public] [function] with the
144144
`proc_macro_derive` attribute and a signature of `(TokenStream) -> TokenStream`.
145145

146146
r[macro.proc.derive.namespace]
147-
The `proc_macro_derive` attribute defines the custom derive in the [macro namespace] in the root of the crate.
147+
The `proc_macro_derive` attribute defines the custom derive in the [derive sub-namespace][sub-namespace] of the [macro namespace] in the root of the crate.
148148

149149
r[macro.proc.derive.output]
150150
The input [`TokenStream`] is the token stream of the item that has the `derive`
@@ -240,7 +240,7 @@ including other [attributes] on the [item]. The returned [`TokenStream`]
240240
replaces the [item] with an arbitrary number of [items].
241241

242242
r[macro.proc.attribute.namespace]
243-
The `proc_macro_attribute` attribute defines the attribute in the [macro namespace] in the root of the crate.
243+
The `proc_macro_attribute` attribute defines the attribute in the [attribute sub-namespace][sub-namespace] of the [macro namespace] in the root of the crate.
244244

245245
For example, this attribute macro takes the input stream and returns it as is,
246246
effectively being the no-op of attributes.
@@ -399,6 +399,7 @@ their equivalent `#[doc = r"str"]` attributes when passed to macros.
399399
[item]: items.md
400400
[items]: items.md
401401
[macro namespace]: names/namespaces.md
402+
[sub-namespace]: names/namespaces.md#sub-namespaces
402403
[module]: items/modules.md
403404
[patterns]: patterns.md
404405
[public]: visibility-and-privacy.md

0 commit comments

Comments
 (0)