You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/names/namespaces.md
+9
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
+
r[names.namespaces]
1
2
# Namespaces
2
3
4
+
r[names.namespaces.intro]
3
5
A *namespace* is a logical grouping of declared [names]. Names are segregated
4
6
into separate namespaces based on the kind of entity the name refers to.
5
7
Namespaces allow the occurrence of a name in one namespace to not conflict
@@ -10,6 +12,7 @@ entities. The usage of a name will look for the declaration of that name in
10
12
different namespaces, based on the context, as described in the [name
11
13
resolution] chapter.
12
14
15
+
r[names.namespaces.kinds]
13
16
The following is a list of namespaces, with their corresponding entities:
14
17
15
18
* Type Namespace
@@ -81,34 +84,40 @@ fn example<'Foo>(f: Foo) {
81
84
}
82
85
```
83
86
87
+
r[names.namespaces.without]
84
88
## Named entities without a namespace
85
89
86
90
The following entities have explicit names, but the names are not a part of
87
91
any specific namespace.
88
92
89
93
### Fields
90
94
95
+
r[names.namespaces.without.fields]
91
96
Even though struct, enum, and union fields are named, the named fields do not
92
97
live in an explicit namespace. They can only be accessed via a [field
93
98
expression], which only inspects the field names of the specific type being
94
99
accessed.
95
100
96
101
### Use declarations
97
102
103
+
r[names.namespaces.without.use]
98
104
A [use declaration] has named aliases that it imports into scope, but the
99
105
`use` item itself does not belong to a specific namespace. Instead, it can
100
106
introduce aliases into multiple namespaces, depending on the item kind being
101
107
imported.
102
108
109
+
r[names.namespaces.sub-namespaces]
103
110
## Sub-namespaces
104
111
112
+
r[names.namespaces.sub-namespaces.intro]
105
113
The macro namespace is split into two sub-namespaces: one for [bang-style macros] and one for [attributes].
106
114
When an attribute is resolved, any bang-style macros in scope will be ignored.
107
115
And conversely resolving a bang-style macro will ignore attribute macros in scope.
108
116
This prevents one style from shadowing another.
109
117
110
118
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.
111
119
120
+
r[names.namespaces.sub-namespaces.use-shadow]
112
121
It is still an error for a [`use` import] to shadow another macro, regardless of their sub-namespaces.
0 commit comments