DEV Community

Discussion on: Adding our own custom statement to Rust language

Collapse
 
chayimfriedman2 profile image
Chayim Friedman

AFAIK, the Rust compiler never changes the AST. It should be a complete mirror of the source code. Desugaring happens on the HIR. But nice write-up :)

Collapse
 
drazendotlic profile image
Drazen Dotlic

I think the translation should happen before HIR, no? I mean, unless cleanly translates into not if, which then translates into jumps in the HIR, no? I admittedly know only general compiler techniques, not rustic.
I concur about the nice write-up though 😃

Collapse
 
chayimfriedman2 profile image
Chayim Friedman

HIR doesn't contain jumps. MIR contains them. HIR is very similar to the AST, and is directly generated from (then converted to type-checked HIR during typeck). HIR desugars features like async/await (to generators), for and while let loops (to loop with breaks), if let to match, and more.