]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
1 | # AST Validation |
2 | ||
9ffffee4 FG |
3 | _AST validation_ is a separate AST pass that visits each |
4 | item in the tree and performs simple checks. This pass | |
5 | doesn't perform any complex analysis, type checking or | |
6 | name resolution. | |
7 | ||
8 | Before performing any validation, the compiler first expands | |
9 | the macros. Then this pass performs validations to check | |
10 | that each AST item is in the correct state. And when this pass | |
11 | is done, the compiler runs the crate resolution pass. | |
12 | ||
13 | ## Validations | |
14 | ||
15 | Validations are defined in `AstValidator` type, which | |
16 | itself is located in `rustc_ast_passes` crate. This | |
17 | type implements various simple checks which emit errors | |
18 | when certain language rules are broken. | |
19 | ||
20 | In addition, `AstValidator` implements `Visitor` trait | |
21 | that defines how to visit AST items (which can be functions, | |
22 | traits, enums, etc). | |
23 | ||
24 | For each item, visitor performs specific checks. For | |
25 | example, when visiting a function declaration, | |
26 | `AstValidator` checks that the function has: | |
27 | ||
28 | * no more than `u16::MAX` parameters; | |
29 | * c-variadic functions are declared with at least one named argument; | |
30 | * c-variadic argument goes the last in the declaration; | |
31 | * documentation comments aren't applied to function parameters; | |
32 | * and other validations. |