Skip to main content

ExprKind

Enum ExprKind 

Source
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.

Fields

§path: Option<Path>
§name: Ident
§

Unary

Fields

§operand: Box<Expr>
§

Binary

Fields

§lhs: Box<Expr>
§rhs: Box<Expr>
§

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.

Fields

§callee: Box<Expr>
§args: Vec<Expr>
§

Field

Fields

§base: Box<Expr>
§name: Ident
§

MethodCall

receiver.method(args...) (spec 2.5): a method call, value.name(args).

Fields

§receiver: Box<Expr>
§method: Ident
§args: Vec<Expr>
§

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.

Fields

§base: Box<Expr>
§index: Box<Expr>
§

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.

Fields

§operand: Box<Expr>
§

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.

Fields

§scrutinee: Box<Expr>
§

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.

Fields

§path: Option<Path>
§name: Ident
§fields: Vec<(Ident, Expr)>
§

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.

Fields

§cond: Box<Expr>
§then: Block
§else_: Option<Block>
§

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.

Fields

§pattern: Pattern
§value: Box<Expr>
§then: Block
§else_: Option<Block>
§span: Span
§

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.

Fields

§params: Vec<Ident>
§body: Box<Expr>
§span: Span
§

Cast

expr as T (M4 spec 2.9), binding tighter than *. ty is a plain name with no path and no generic arguments.

Fields

§expr: Box<Expr>
§span: Span
§

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.

Fields

§name: Ident
§format: (String, Span)
§args: Vec<Expr>

Trait Implementations§

Source§

impl Clone for ExprKind

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExprKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ExprKind

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ExprKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.