pub enum ExprKind {
Show 21 variants
Integer(String),
Float(String),
Bool(bool),
String(String),
Path {
path: Option<Path>,
name: Ident,
},
Unary {
op: UnaryOp,
operand: Box<Expr>,
},
Binary {
op: BinaryOp,
lhs: Box<Expr>,
rhs: Box<Expr>,
},
Call {
callee: Box<Expr>,
args: Vec<Expr>,
},
Field {
base: Box<Expr>,
name: Ident,
},
MethodCall {
receiver: Box<Expr>,
method: Ident,
args: Vec<Expr>,
},
Index {
base: Box<Expr>,
index: Box<Expr>,
},
Try {
operand: Box<Expr>,
},
Match {
scrutinee: Box<Expr>,
arms: Vec<MatchArm>,
},
VecLit(Vec<Expr>),
StructLit {
path: Option<Path>,
name: Ident,
fields: Vec<(Ident, Expr)>,
},
Block(Block),
If {
cond: Box<Expr>,
then: Block,
else_: Option<Block>,
},
IfLet {
pattern: Pattern,
value: Box<Expr>,
then: Block,
else_: Option<Block>,
span: Span,
},
Closure {
params: Vec<Ident>,
body: Box<Expr>,
span: Span,
},
Cast {
expr: Box<Expr>,
ty: TypeExpr,
span: Span,
},
Intrinsic {
name: Ident,
format: (String, Span),
args: Vec<Expr>,
},
}Variants§
Integer(String)
Raw digits, as lexed: the type checker decides the type from context.
Float(String)
Raw digits.digits, as lexed.
Bool(bool)
String(String)
Raw text between the quotes, as written: escapes are copied unchanged into the generated Rust, which resolves them.
Path
name, module::name, or module::Type::name (spec 2.5, 2.10,
3.1): a plain name, a module-qualified one, or a
module-and-type-qualified one (an associated function or enum
variant reached through a module), with paths now growing to any
depth as nested modules do. path covers every segment before the
final one (the module chain, and the type name when the path names
an associated function or a variant); name is that final segment,
the thing actually read or called. Whether path’s segments name a
deeper module chain than milestone 3 resolves, a single module, or a
type in this file (the two-way ambiguity a bare one-segment path
carries, spec 2.10) is the compiler’s resolver’s job, not the
parser’s.
Unary
Binary
Call
callee(args...). callee must be a Path, naming a plain
function or an associated function (spec 2.5); x.f(args) is
method-call syntax and parses as ExprKind::MethodCall instead,
never as a Call with a Field callee. Any other callee shape
(calling the result of a grouped expression, an index, and so on)
is rejected: V0002 from the parser, and defensively V0001 from
the type checker if such a node ever reaches it.
Field
MethodCall
receiver.method(args...) (spec 2.5): a method call, value.name(args).
Index
base[index] (spec 2.6): indexing, v[i]. Whether base is
actually a Vec, and whether index is a usize, is the type
checker’s job.
Try
operand? (spec 2.8): propagates an Err out of the enclosing
function. Whether operand is actually a Result compatible with
the function’s return type is the type checker’s job.
Match
match scrutinee { arms... } (spec 2.3), an expression like if.
It may also stand as a statement without a trailing ;, the same
as if and a bare block, distinguished the same way by
Stmt::Expr’s has_semi.
VecLit(Vec<Expr>)
vec![a, b, c] (spec 2.9), a compiler intrinsic like println!,
not a macro system: its elements, each an owned slot.
StructLit
Name { field: expr, ... }, or path::Name { field: expr, ... }
with a module path of any depth and an optional crate::,
self::, or super:: prefix (spec 2.10, 3.1). Never parsed in
condition position.
Block(Block)
If
if cond { ... } or if cond { ... } else { ... }. cond is
parsed in condition position, so no struct literal is parsed
directly in it. An else if is represented as else_ holding a
synthetic block whose only content is the nested If as its tail
expression.
IfLet
if let pattern = value { ... }, with an optional else (M4 spec
2.4). value is parsed in condition position, as if’s condition
is, and else if and else if let are a synthetic block holding
the nested expression as its tail, as for ExprKind::If.
Closure
|params| body (M4 spec 2.2). The parameters carry no type; how
many there may be, and where a closure may appear, is the
checker’s to decide.
Cast
expr as T (M4 spec 2.9), binding tighter than *. ty is a
plain name with no path and no generic arguments.
Intrinsic
println!(format, args...) or format!(format, args...) (spec
2.9): compiler intrinsics sharing one shape, told apart by name.
format keeps the format string’s raw text and span; placeholder
checking is the type checker’s job.