pub enum ExprKind {
Show 18 variants
Integer(String),
Float(String),
Bool(bool),
String(String),
Path {
module: Option<Ident>,
type_: Option<Ident>,
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 {
module: Option<Ident>,
name: Ident,
fields: Vec<(Ident, Expr)>,
},
Block(Block),
If {
cond: Box<Expr>,
then: Block,
else_: Option<Block>,
},
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): a
plain name, a module-qualified one, or a module-and-type-qualified
one (an associated function or enum variant reached through a
module). A two-segment path fills module only; a three-segment
one fills both module and type_. A path longer than three
segments is rejected with V0001 (still built from its first two
segments and its last, so later passes have something to work
with). Resolving type_ is milestone 2 tasks 6 and 7’s job; until
then the compiler rejects it with V0001 rather than silently
mis-resolving it.
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 module::Name { field: expr, ... }
(spec 2.10). 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.
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.