Skip to main content

ExprKind

Enum ExprKind 

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

Fields

§module: Option<Ident>
§type_: Option<Ident>
§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 module::Name { field: expr, ... } (spec 2.10). Never parsed in condition position.

Fields

§module: Option<Ident>
§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>
§

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.