Skip to content

Commit 615b4ce

Browse files
authored
Merge pull request #1737 from ehuss/rules-names
Add rule identifiers to names chapters
2 parents b4f049d + 5db59a4 commit 615b4ce

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

Diff for: src/names/namespaces.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
r[names.namespaces]
12
# Namespaces
23

4+
r[names.namespaces.intro]
35
A *namespace* is a logical grouping of declared [names]. Names are segregated
46
into separate namespaces based on the kind of entity the name refers to.
57
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
1012
different namespaces, based on the context, as described in the [name
1113
resolution] chapter.
1214

15+
r[names.namespaces.kinds]
1316
The following is a list of namespaces, with their corresponding entities:
1417

1518
* Type Namespace
@@ -81,34 +84,40 @@ fn example<'Foo>(f: Foo) {
8184
}
8285
```
8386

87+
r[names.namespaces.without]
8488
## Named entities without a namespace
8589

8690
The following entities have explicit names, but the names are not a part of
8791
any specific namespace.
8892

8993
### Fields
9094

95+
r[names.namespaces.without.fields]
9196
Even though struct, enum, and union fields are named, the named fields do not
9297
live in an explicit namespace. They can only be accessed via a [field
9398
expression], which only inspects the field names of the specific type being
9499
accessed.
95100

96101
### Use declarations
97102

103+
r[names.namespaces.without.use]
98104
A [use declaration] has named aliases that it imports into scope, but the
99105
`use` item itself does not belong to a specific namespace. Instead, it can
100106
introduce aliases into multiple namespaces, depending on the item kind being
101107
imported.
102108

109+
r[names.namespaces.sub-namespaces]
103110
## Sub-namespaces
104111

112+
r[names.namespaces.sub-namespaces.intro]
105113
The macro namespace is split into two sub-namespaces: one for [bang-style macros] and one for [attributes].
106114
When an attribute is resolved, any bang-style macros in scope will be ignored.
107115
And conversely resolving a bang-style macro will ignore attribute macros in scope.
108116
This prevents one style from shadowing another.
109117

110118
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.
111119

120+
r[names.namespaces.sub-namespaces.use-shadow]
112121
It is still an error for a [`use` import] to shadow another macro, regardless of their sub-namespaces.
113122

114123
[`cfg` attribute]: ../conditional-compilation.md#the-cfg-attribute

Diff for: src/names/preludes.md

+38-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
r[names.preludes]
12
# Preludes
23

4+
r[names.preludes.intro]
35
A *prelude* is a collection of names that are automatically brought into scope
46
of every module in a crate.
57

@@ -8,6 +10,7 @@ queried during [name resolution]. For example, even though something like
810
[`Box`] is in scope in every module, you cannot refer to it as `self::Box`
911
because it is not a member of the current module.
1012

13+
r[names.preludes.kinds]
1114
There are several different preludes:
1215

1316
- [Standard library prelude]
@@ -16,9 +19,13 @@ There are several different preludes:
1619
- [`macro_use` prelude]
1720
- [Tool prelude]
1821

22+
r[names.preludes.std]
1923
## Standard library prelude
2024

25+
r[names.preludes.std.intro]
2126
Each crate has a standard library prelude, which consists of the names from a single standard library module.
27+
28+
r[names.preludes.std.module]
2229
The module used depends on the crate's edition, and on whether the [`no_std` attribute] is applied to the crate:
2330

2431
Edition | `no_std` not applied | `no_std` applied
@@ -35,16 +42,22 @@ Edition | `no_std` not applied | `no_std` applied
3542
>
3643
> [`core::prelude::rust_2015`] and [`core::prelude::rust_2018`] have the same contents as [`core::prelude::v1`].
3744
45+
r[names.preludes.extern]
3846
## Extern prelude
3947

48+
r[names.preludes.extern.intro]
4049
External crates imported with [`extern crate`] in the root module or provided
4150
to the compiler (as with the `--extern` flag with `rustc`) are added to the
4251
*extern prelude*. If imported with an alias such as `extern crate orig_name as
4352
new_name`, then the symbol `new_name` is instead added to the prelude.
4453

45-
The [`core`] crate is always added to the extern prelude. The [`std`] crate is
46-
added as long as the [`no_std` attribute] is not specified in the crate root.
54+
r[names.preludes.extern.core]
55+
The [`core`] crate is always added to the extern prelude.
56+
57+
r[names.preludes.extern.std]
58+
The [`std`] crate is added as long as the [`no_std` attribute] is not specified in the crate root.
4759

60+
r[names.preludes.extern.edition2018]
4861
> **Edition differences**: In the 2015 edition, crates in the extern prelude
4962
> cannot be referenced via [use declarations], so it is generally standard
5063
> practice to include `extern crate` declarations to bring them into scope.
@@ -70,19 +83,27 @@ See https://github.com/rust-lang/rust/issues/57288 for more about the
7083
alloc/test limitation.
7184
-->
7285
86+
r[names.preludes.extern.no_std]
7387
### The `no_std` attribute
7488
89+
r[names.preludes.extern.no_std.intro]
7590
By default, the standard library is automatically included in the crate root
7691
module. The [`std`] crate is added to the root, along with an implicit
7792
[`macro_use` attribute] pulling in all macros exported from `std` into the
7893
[`macro_use` prelude]. Both [`core`] and [`std`] are added to the [extern
7994
prelude].
8095
96+
r[names.preludes.extern.no_std.allowed-positions]
8197
The *`no_std` [attribute]* may be applied at the crate level to prevent the
82-
[`std`] crate from being automatically added into scope. It does three things:
98+
[`std`] crate from being automatically added into scope.
8399
100+
It does three things:
101+
102+
r[names.preludes.extern.no_std.extern]
84103
* Prevents `std` from being added to the [extern prelude](#extern-prelude).
104+
r[names.preludes.extern.no_std.module]
85105
* Affects which module is used to make up the [standard library prelude] (as described above).
106+
r[names.preludes.extern.no_std.core]
86107
* Injects the [`core`] crate into the crate root instead of [`std`], and pulls
87108
in all macros exported from `core` in the [`macro_use` prelude].
88109
@@ -95,10 +116,15 @@ The *`no_std` [attribute]* may be applied at the crate level to prevent the
95116
> [!WARNING]
96117
> Using `no_std` does not prevent the standard library from being linked in. It is still valid to put `extern crate std;` into the crate and dependencies can also link it in.
97118
119+
r[names.preludes.lang]
98120
## Language prelude
99121
122+
r[names.preludes.lang.intro]
100123
The language prelude includes names of types and attributes that are built-in
101-
to the language. The language prelude is always in scope. It includes the following:
124+
to the language. The language prelude is always in scope.
125+
126+
r[names.preludes.lang.entities]
127+
It includes the following:
102128
103129
* [Type namespace]
104130
* [Boolean type] --- `bool`
@@ -109,25 +135,33 @@ to the language. The language prelude is always in scope. It includes the follow
109135
* [Macro namespace]
110136
* [Built-in attributes]
111137
138+
r[names.preludes.macro_use]
112139
## `macro_use` prelude
113140
141+
r[names.preludes.macro_use.intro]
114142
The `macro_use` prelude includes macros from external crates that were
115143
imported by the [`macro_use` attribute] applied to an [`extern crate`].
116144
145+
r[names.preludes.tool]
117146
## Tool prelude
118147
148+
r[names.preludes.tool.intro]
119149
The tool prelude includes tool names for external tools in the [type
120150
namespace]. See the [tool attributes] section for more details.
121151
152+
r[names.preludes.no_implicit_prelude]
122153
## The `no_implicit_prelude` attribute
123154
155+
r[names.preludes.no_implicit_prelude.intro]
124156
The *`no_implicit_prelude` [attribute]* may be applied at the crate level or
125157
on a module to indicate that it should not automatically bring the [standard
126158
library prelude], [extern prelude], or [tool prelude] into scope for that
127159
module or any of its descendants.
128160
161+
r[names.preludes.no_implicit_prelude.lang]
129162
This attribute does not affect the [language prelude].
130163
164+
r[names.preludes.no_implicit_prelude.edition2018]
131165
> **Edition differences**: In the 2015 edition, the `no_implicit_prelude`
132166
> attribute does not affect the [`macro_use` prelude], and all macros exported
133167
> from the standard library are still included in the `macro_use` prelude.

0 commit comments

Comments
 (0)