@@ -23,8 +23,8 @@ macros, values, types, lifetimes), and names may be valid at different (nested)
2323scopes.
2424Also, different types of names can fail resolution differently, and
2525failures 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
2828that module.
2929On the other hand, in a function body scope, failure requires that a
3030name be absent from the block we are in, all outer scopes, and the global scope.
@@ -46,22 +46,23 @@ let y: x = 2;
4646
4747How do we know on line 3 whether ` x ` is a type (` u32 ` ) or a value (1)?
4848These 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
5151namespaces and therefore can co-exist.
5252
5353The 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.
5657Macro expansion and name resolution communicate with each other via the
5758[ ` ResolverAstLoweringExt ` ] trait.
5859
5960The input to the second phase is the syntax tree, produced by parsing input
6061files and expanding ` macros ` .
6162This phase produces links from all the names in the
6263source 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
6566unused items.
6667
6768A 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
9596them.
9697
9798In 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
104103A 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
107106part of another, it doesn't mean a name visible in the outer scope is also
108107visible 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
160159To perform the name resolution of the whole crate, the syntax tree is traversed
161160top-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 ` ]
164163hierarchy.
165164
166165There are some exceptions to this.
0 commit comments