Skip to content

Commit 7f79944

Browse files
authored
Merge pull request #1043 from ehuss/sub-namespaces
Document sub-namespaces.
2 parents dc3233e + 222c426 commit 7f79944

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/names/namespaces.md

+16
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,40 @@ imported.
104104

105105
<!-- TODO: describe how `use` works on the use-declarations page, and link to it here. -->
106106

107+
## Sub-namespaces
108+
109+
The macro namespace is split into two sub-namespaces: one for [bang-style macros] and one for [attributes].
110+
When an attribute is resolved, any bang-style macros in scope will be ignored.
111+
And conversely resolving a bang-style macro will ignore attribute macros in scope.
112+
This prevents one style from shadowing another.
113+
114+
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.
115+
116+
It is still an error for a [`use` import] to shadow another macro, regardless of their sub-namespaces.
117+
107118
[^rustc-lifetime-shadow]: `rustc` currently warns about shadowing when using
108119
the same name for a label and lifetime in the same scope, but it still
109120
treats them independently. This is intended as a future-compatibility
110121
warning about a possible extension to the language. See [PR
111122
#24162](https://github.com/rust-lang/rust/pull/24162).
112123

124+
[`cfg` attribute]: ../conditional-compilation.md#the-cfg-attribute
125+
[`cfg` macro]: ../conditional-compilation.md#the-cfg-macro
113126
[`for`]: ../expressions/loop-expr.md#iterator-loops
114127
[`if let`]: ../expressions/if-expr.md#if-let-expressions
115128
[`let`]: ../statements.md#let-statements
116129
[`macro_rules` declarations]: ../macros-by-example.md
117130
[`match`]: ../expressions/match-expr.md
118131
[`Self` constructors]: ../paths.md#self-1
119132
[`Self` type]: ../paths.md#self-1
133+
[`use` import]: ../items/use-declarations.md
120134
[`while let`]: ../expressions/loop-expr.md#predicate-pattern-loops
121135
[Associated const declarations]: ../items/associated-items.md#associated-constants
122136
[Associated function declarations]: ../items/associated-items.md#associated-functions-and-methods
123137
[Associated type declarations]: ../items/associated-items.md#associated-types
124138
[Attribute macros]: ../procedural-macros.md#attribute-macros
139+
[attributes]: ../attributes.md
140+
[bang-style macros]: ../macros.md
125141
[boolean]: ../types/boolean.md
126142
[Built-in attributes]: ../attributes.md#built-in-attributes-index
127143
[closure parameters]: ../expressions/closure-expr.md

0 commit comments

Comments
 (0)