Skip to content

Commit c3680de

Browse files
committed
reflow
1 parent e7704aa commit c3680de

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

src/name-resolution.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ macros, values, types, lifetimes), and names may be valid at different (nested)
2323
scopes.
2424
Also, different types of names can fail resolution differently, and
2525
failures can happen differently at different scopes.
26-
For example, in a module
27-
scope, failure means no unexpanded macros and no unresolved glob imports in
26+
For example, in a module scope,
27+
failure means no unexpanded macros and no unresolved glob imports in
2828
that module.
2929
On the other hand, in a function body scope, failure requires that a
3030
name be absent from the block we are in, all outer scopes, and the global scope.
@@ -46,22 +46,23 @@ let y: x = 2;
4646

4747
How do we know on line 3 whether `x` is a type (`u32`) or a value (1)?
4848
These conflicts are resolved during name resolution.
49-
In this specific case, name
50-
resolution defines that type names and variable names live in separate
49+
In this specific case,
50+
name resolution defines that type names and variable names live in separate
5151
namespaces and therefore can co-exist.
5252

5353
The name resolution in Rust is a two-phase process.
54-
In the first phase, which runs
55-
during `macro` expansion, we build a tree of modules and resolve imports.
54+
In the first phase,
55+
which runs during `macro` expansion,
56+
we build a tree of modules and resolve imports.
5657
Macro expansion and name resolution communicate with each other via the
5758
[`ResolverAstLoweringExt`] trait.
5859

5960
The input to the second phase is the syntax tree, produced by parsing input
6061
files and expanding `macros`.
6162
This phase produces links from all the names in the
6263
source to relevant places where the name was introduced.
63-
It also generates
64-
helpful error messages, like typo suggestions, traits to import or lints about
64+
It also generates helpful error messages,
65+
like typo suggestions, traits to import or lints about
6566
unused items.
6667

6768
A successful run of the second phase ([`Resolver::resolve_crate`]) creates kind
@@ -95,15 +96,13 @@ namespaces, the resolver keeps them separated and builds separate structures for
9596
them.
9697

9798
In other words, when the code talks about namespaces, it doesn't mean the module
98-
hierarchy, it's types vs.
99-
values vs.
100-
macros.
99+
hierarchy, it's types versus values versus macros.
101100

102101
## Scopes and ribs
103102

104103
A name is visible only in certain area in the source code.
105-
This forms a
106-
hierarchical structure, but not necessarily a simple one ‒ if one scope is
104+
This forms a hierarchical structure,
105+
but not necessarily a simple one ‒ if one scope is
107106
part of another, it doesn't mean a name visible in the outer scope is also
108107
visible in the inner scope, or that it refers to the same thing.
109108

@@ -159,8 +158,8 @@ blocks), which isn't a full namespace in its own right.
159158

160159
To perform the name resolution of the whole crate, the syntax tree is traversed
161160
top-down and every encountered name is resolved.
162-
This works for most kinds of
163-
names, because at the point of use of a name it is already introduced in the [`Rib`]
161+
This works for most kinds of names,
162+
because at the point of use of a name it is already introduced in the [`Rib`]
164163
hierarchy.
165164

166165
There are some exceptions to this.

0 commit comments

Comments
 (0)