pub enum Stmt {
Let {
is_mut: bool,
name: String,
ty: Option<TypeExpr>,
init: Expr,
span: Span,
},
If {
cond: Expr,
then_block: Block,
else_branch: Option<ElseBranch>,
span: Span,
},
While {
cond: Expr,
body: Block,
span: Span,
},
For {
var: String,
iter: Expr,
body: Block,
span: Span,
},
Return {
value: Option<Expr>,
span: Span,
},
Break {
span: Span,
},
Continue {
span: Span,
},
Defer {
expr: Expr,
span: Span,
},
Expr {
expr: Expr,
span: Span,
},
}Expand description
a statement. if/else, while, for ... in ..., return, break,
continue, and defer expr are all statements – not expressions; there is
no Expr::If in v1. an if chains through ElseBranch::If for
else if.
Variants§
Let
let name = init or let mut name = init, with an optional : ty. the
initializer is required (no uninitialized bindings); the type is inferred
from init when omitted.
If
if cond { ... } with an optional else (a block, or another if for
an else if chain). a statement, not an expression – there is no
let x = if c { a } else { b } in v1.
While
while cond { ... }.
For
for var in iter { ... }. iter is any expression that yields an
iterable; a range is just one kind of iterable. kept as a For node, not
lowered to a while.
Return
return or return expr. the value is optional – a bare return in a
void function is legal.
Break
break. no labels, no value in v1.
Continue
continue. no labels, no value in v1.
Defer
defer expr – expr runs at scope exit, LIFO with other defers in the
same scope.
Expr
an expression used as a statement (expr ;). its value is discarded.