Skip to content

Commit 29b0d1c

Browse files
phanschmark-i-m
authored andcommitted
Name resolution: Add intro section
1 parent 69a3667 commit 29b0d1c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/name-resolution.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# Name resolution
22

3-
The name resolution is a two-phase process. In the first phase, which runs
3+
## Basics
4+
5+
In our programs we can refer to variables, types, functions, etc, by giving them
6+
a name. These names are not always unique. For example, take this valid Rust
7+
program:
8+
9+
```rust
10+
type x = u32;
11+
let x: x = 1;
12+
let y: x = 2;
13+
```
14+
15+
How do we know on line 3 whether `x` is a type (u32) or a value (1)?
16+
These conflicts are resolved in `librustc_resolve`.
17+
In this specific case, name resolution defines that type names and variable
18+
names live in separate namespaces and therefore can co-exist.
19+
20+
The name resolution in Rust is a two-phase process. In the first phase, which runs
421
during macro expansion, we build a tree of modules and resolve imports. Macro
522
expansion and name resolution communicate with each other via the `Resolver`
623
trait, defined in `libsyntax`.

0 commit comments

Comments
 (0)