Skip to content

Commit d1ebca1

Browse files
authored
Rollup merge of rust-lang#124091 - jieyouxu:ast-validation-top-level-docs, r=wesleywiser
Update AST validation module docs Drive-by doc update for AST validation pass: - Syntax extensions are replaced by proc macros. - Add rationale for why AST validation pass need to be run post-expansion and why the pass is needed in the first place. This was discussed during this week's [rustc-dev-guide reading club](https://rust-lang.zulipchat.com/#narrow/stream/196385-t-compiler.2Fwg-rustc-dev-guide), and the rationale was explained by cc ``@bjorn3.``
2 parents 72f2d11 + 0e35216 commit d1ebca1

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
// Validate AST before lowering it to HIR.
2-
//
3-
// This pass is supposed to catch things that fit into AST data structures,
4-
// but not permitted by the language. It runs after expansion when AST is frozen,
5-
// so it can check for erroneous constructions produced by syntax extensions.
6-
// This pass is supposed to perform only simple checks not requiring name resolution
7-
// or type checking or some other kind of complex analysis.
1+
//! Validate AST before lowering it to HIR.
2+
//!
3+
//! This pass intends to check that the constructed AST is *syntactically valid* to allow the rest
4+
//! of the compiler to assume that the AST is valid. These checks cannot be performed during parsing
5+
//! because attribute macros are allowed to accept certain pieces of invalid syntax such as a
6+
//! function without body outside of a trait definition:
7+
//!
8+
//! ```ignore (illustrative)
9+
//! #[my_attribute]
10+
//! mod foo {
11+
//! fn missing_body();
12+
//! }
13+
//! ```
14+
//!
15+
//! These checks are run post-expansion, after AST is frozen, to be able to check for erroneous
16+
//! constructions produced by proc macros. This pass is only intended for simple checks that do not
17+
//! require name resolution or type checking, or other kinds of complex analysis.
818
919
use itertools::{Either, Itertools};
1020
use rustc_ast::ptr::P;

0 commit comments

Comments
 (0)