Skip to content

Commit cb22326

Browse files
committed
Minor edits
- un-codeblock some words - uncomment the last paragraph (it's useful to know this)
1 parent 172d38e commit cb22326

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/name-resolution.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
<!-- toc -->
44

55
In the previous chapters, we saw how the [*Abstract Syntax Tree* (`AST`)][ast]
6-
is built with all `macros` expanded. We saw how doing that requires doing some
7-
name resolution to resolve imports and `macro` names. In this chapter, we show
6+
is built with all macros expanded. We saw how doing that requires doing some
7+
name resolution to resolve imports and macro names. In this chapter, we show
88
how this is actually done and more.
99

1010
[ast]: ./ast-validation.md
1111

12-
In fact, we don't do full name resolution during `macro` expansion -- we only
13-
resolve imports and `macros` at that time. This is required to know what to even
14-
expand. Later, after we have the whole `AST`, we do full name resolution to
12+
In fact, we don't do full name resolution during macro expansion -- we only
13+
resolve imports and macros at that time. This is required to know what to even
14+
expand. Later, after we have the whole AST, we do full name resolution to
1515
resolve all names in the crate. This happens in [`rustc_resolve::late`][late].
16-
Unlike during `macro` expansion, in this late expansion, we only need to try to
16+
Unlike during macro expansion, in this late expansion, we only need to try to
1717
resolve a name once, since no new names can be added. If we fail to resolve a
1818
name, then it is a compiler error.
1919

20-
Name resolution can be complex. There are different namespaces (e.g.
21-
`macros`, values, types, lifetimes), and names may be valid at different (nested)
20+
Name resolution is complex. There are different namespaces (e.g.
21+
macros, values, types, lifetimes), and names may be valid at different (nested)
2222
scopes. Also, different types of names can fail resolution differently, and
2323
failures can happen differently at different scopes. For example, in a module
24-
scope, failure means no unexpanded `macros` and no unresolved glob imports in
24+
scope, failure means no unexpanded macros and no unresolved glob imports in
2525
that module. On the other hand, in a function body scope, failure requires that a
2626
name be absent from the block we are in, all outer scopes, and the global
2727
scope.
@@ -53,7 +53,7 @@ expansion and name resolution communicate with each other via the
5353
The input to the second phase is the syntax tree, produced by parsing input
5454
files and expanding `macros`. This phase produces links from all the names in the
5555
source to relevant places where the name was introduced. It also generates
56-
helpful error messages, like typo suggestions, `trait`s to import or lints about
56+
helpful error messages, like typo suggestions, traits to import or lints about
5757
unused items.
5858

5959
A successful run of the second phase ([`Resolver::resolve_crate`]) creates kind
@@ -85,7 +85,7 @@ namespaces, the resolver keeps them separated and builds separate structures for
8585
them.
8686

8787
In other words, when the code talks about namespaces, it doesn't mean the module
88-
hierarchy, it's types vs. values vs. `macros`.
88+
hierarchy, it's types vs. values vs. macros.
8989

9090
## Scopes and ribs
9191

@@ -105,12 +105,12 @@ example:
105105
modules.
106106
* Introducing a `let` binding ‒ this can shadow another binding with the same
107107
name.
108-
* Macro expansion border ‒ to cope with `macro` hygiene.
108+
* Macro expansion border ‒ to cope with macro hygiene.
109109

110110
When searching for a name, the stack of [`ribs`] is traversed from the innermost
111111
outwards. This helps to find the closest meaning of the name (the one not
112112
shadowed by anything else). The transition to outer [`Rib`] may also affect
113-
what names are usable ‒ if there are nested functions (not `closure`s),
113+
what names are usable ‒ if there are nested functions (not closures),
114114
the inner one can't access parameters and local bindings of the outer one,
115115
even though they should be visible by ordinary scoping rules. An example:
116116

@@ -150,14 +150,14 @@ used even before encountered ‒ therefore every block needs to be first scanned
150150
for items to fill in its [`Rib`].
151151

152152
Other, even more problematic ones, are imports which need recursive fixed-point
153-
resolution and `macros`, that need to be resolved and expanded before the rest of
153+
resolution and macros, that need to be resolved and expanded before the rest of
154154
the code can be processed.
155155

156156
Therefore, the resolution is performed in multiple stages.
157157

158158
## Speculative crate loading
159159

160-
To give useful errors, `rustc` suggests importing paths into scope if they're
160+
To give useful errors, rustc suggests importing paths into scope if they're
161161
not found. How does it do this? It looks through every module of every crate
162162
and looks for possible matches. This even includes crates that haven't yet
163163
been loaded!
@@ -176,7 +176,7 @@ To tell the difference between speculative loads and loads initiated by the
176176
user, [`rustc_resolve`] passes around a `record_used` parameter, which is `false` when
177177
the load is speculative.
178178

179-
<!-- ## TODO: [#16](https://github.com/rust-lang/rustc-dev-guide/issues/16)
179+
## TODO: [#16](https://github.com/rust-lang/rustc-dev-guide/issues/16)
180180

181181
This is a result of the first pass of learning the code. It is definitely
182182
incomplete and not detailed enough. It also might be inaccurate in places.
@@ -190,4 +190,4 @@ Still, it probably provides useful first guidepost to what happens in there.
190190
* The overall strategy description is a bit vague.
191191
* Where does the name `Rib` come from?
192192
* Does this thing have its own tests, or is it tested only as part of some e2e
193-
testing? -->
193+
testing?

0 commit comments

Comments
 (0)