Skip to content

Commit 54cfdd7

Browse files
dbeliktshepang
authored andcommitted
Update ast-validation.md
1 parent 566124f commit 54cfdd7

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/ast-validation.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
# AST Validation
22

3-
AST validation is the process of checking various correctness properties about
4-
the AST after macro expansion.
3+
* [About](#about)
4+
* [Validation](#validation)
55

6-
**TODO**: write this chapter. [#656](https://github.com/rust-lang/rustc-dev-guide/issues/656)
6+
## About
7+
8+
_AST validation_ is a separate AST pass that visits each
9+
item in the tree and performs simple checks. This pass
10+
doesn't perform any complex analysis, type checking or
11+
name resolution.
12+
13+
Before performing any validation, the compiler first expands
14+
the macros. Then this pass performs validations to check
15+
that each AST item is in the correct state. And when this pass
16+
is done, the compiler runs the crate resolution pass.
17+
18+
## Validations
19+
20+
Validations are defined in `AstValidator` class, which
21+
itself is located in `rustc_ast_passes` crate. This
22+
class implements various simple checks which emit errors
23+
when certain language rules are broken.
24+
25+
In addition, `AstValidator` implements `Visitor` trait
26+
that defines how to visit AST items (which can be functions,
27+
traits, enums, etc).
28+
29+
For each item, visitor performs specific checks. For
30+
example, when visiting a function declaration,
31+
`AstValidator` checks that the function has:
32+
33+
* no more than `u16::MAX` parameters;
34+
* c-variadic functions are declared with at least one named argument;
35+
* c-variadic argument goes the last in the declaration;
36+
* documentation comments aren't applied to function parameters;
37+
* and other validations.

0 commit comments

Comments
 (0)