Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 25 variants Int { value: i64, span: Span, }, Float { value: f64, span: Span, }, Byte { value: u8, span: Span, }, Str { value: String, span: Span, }, Bool { value: bool, span: Span, }, Ident { name: String, span: Span, }, Paren { inner: Box<Expr>, span: Span, }, Tuple { elems: Vec<Expr>, span: Span, }, ArrayLit { elems: Vec<Expr>, span: Span, }, ArrayRepeat { value: Box<Expr>, count: Box<Expr>, span: Span, }, StructLit { name: String, fields: Vec<FieldInit>, span: Span, }, FieldAccess { obj: Box<Expr>, name: String, span: Span, }, MethodCall { receiver: Box<Expr>, name: String, args: Vec<Expr>, span: Span, }, Call { callee: Box<Expr>, args: Vec<Expr>, span: Span, }, Index { obj: Box<Expr>, index: Box<Expr>, span: Span, }, Try { expr: Box<Expr>, span: Span, }, Unary { op: UnaryOp, operand: Box<Expr>, span: Span, }, Binary { op: BinOp, lhs: Box<Expr>, rhs: Box<Expr>, span: Span, }, Range { start: Option<Box<Expr>>, end: Option<Box<Expr>>, inclusive: bool, span: Span, }, Pipeline { lhs: Box<Expr>, call: Box<Expr>, span: Span, }, Comptime { body: Box<Expr>, span: Span, }, Block { block: Block, span: Span, }, Match { scrutinee: Box<Expr>, arms: Vec<MatchArm>, span: Span, }, OrElse { expr: Box<Expr>, fallback: Box<Expr>, span: Span, }, Interpolation { parts: Vec<InterpPart>, span: Span, },
}
Expand description

an expression. literals, identifiers, parenthesized and tuple expressions, array literals (including the [v; n] repeat form), struct literals, field access, method calls, calls, indexing, ? propagation, unary and binary operators, ranges, the |> pipeline, comptime, block expressions, match, the or fallback, and string interpolation. there is deliberately no If variant – if/else is a Stmt in v1.

nothing is desugared: Expr::Pipeline stays a pipeline (not f(x, a)), Expr::Interpolation stays a parts list (not a + chain), Expr::Match and Expr::Block produce values directly. that faithfulness is what lets Phase 3 diagnostics point at the source as written; lowering happens in Phase 4 codegen.

Variants§

§

Int

an integer literal (already decoded; a leading - is a separate Expr::Unary).

Fields

§value: i64
§span: Span
§

Float

a float literal (already decoded).

Fields

§value: f64
§span: Span
§

Byte

a byte literal b'X', the byte it denotes.

Fields

§value: u8
§span: Span
§

Str

a string literal with no interpolation, escapes already decoded.

Fields

§value: String
§span: Span
§

Bool

a boolean literal, true or false.

Fields

§value: bool
§span: Span
§

Ident

an identifier reference (a variable, a function name, a type name in value position – the parser does not distinguish; Phase 3 resolves it).

Fields

§name: String
§span: Span
§

Paren

( inner ) – a parenthesized expression. kept as a node so the span and the parentheses are visible to diagnostics; semantically transparent.

Fields

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

Tuple

( e1, e2, ... ) – a tuple. a single element with a trailing comma is a one-tuple; without the comma it is just a Expr::Paren.

Fields

§elems: Vec<Expr>
§span: Span
§

ArrayLit

[ e1, e2, ... ] – an array literal listing its elements.

Fields

§elems: Vec<Expr>
§span: Span
§

ArrayRepeat

[ value; count ] – an array literal repeating value count times.

Fields

§value: Box<Expr>
§count: Box<Expr>
§span: Span
§

StructLit

Name { field: e, ... } – a struct literal. name is the struct’s name; whether it names a real struct is Phase 3’s call.

Fields

§name: String
§fields: Vec<FieldInit>
§span: Span
§

FieldAccess

obj.name – field access. distinct from Expr::MethodCall: this is the form with no ( ... ) after the .name.

Fields

§obj: Box<Expr>
§name: String
§span: Span
§

MethodCall

receiver.name(args) – a method call. distinct from a field access followed by a call; Phase 3 resolves it to fn Type.name(self, ...).

Fields

§receiver: Box<Expr>
§name: String
§args: Vec<Expr>
§span: Span
§

Call

callee(args) – a call expression (callee is usually an Expr::Ident, but can be any expression that yields something callable).

Fields

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

Index

obj[index] – an index expression.

Fields

§obj: Box<Expr>
§index: Box<Expr>
§span: Span
§

Try

expr? – error propagation: if expr is an error, return it from the enclosing function; otherwise unwrap it. binds tightest (with ., call, index), so f()?.x is (f()?).x and a + b? is a + (b?).

Fields

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

Unary

a unary-operator application: !operand or -operand.

Fields

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

Binary

a binary-operator application: lhs op rhs. covers arithmetic, comparison, equality, and the boolean && / ||. the or fallback is not here – it is Expr::OrElse.

Fields

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

Range

start .. end or start ..= end – a range. start and end are each optional to leave room for ..end / start.. forms; inclusive is true for ..=. ranges are ordinary expressions (an iterable for for).

Fields

§start: Option<Box<Expr>>
§inclusive: bool
§span: Span
§

Pipeline

lhs |> call – the pipeline operator. kept as a faithful node, NOT lowered to call(lhs, ...); that desugaring is Phase 4 codegen. call is whatever expression followed |> (typically a call or a bare function name); the parser does not rewrite it.

Fields

§lhs: Box<Expr>
§call: Box<Expr>
§span: Span
§

Comptime

comptime body – evaluate body during compilation, embed the result as a constant. a prefix operator at unary precedence, so comptime a + b is (comptime a) + b; body may also be a block expression (comptime { ... }).

Fields

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

Block

{ ...; trailing } used as an expression – its value is the block’s trailing expression (or void). one of only two value-producing block forms; the other is Expr::Match.

Fields

§block: Block
§span: Span
§

Match

match scrutinee { arm, ... } – pattern matching with at least one arm. kept as a faithful node. each arm has a pattern, an optional if guard, and a body (an expression or a block); Phase 3 checks exhaustiveness.

Fields

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

OrElse

expr or fallback – inline fallback for a Result/Option: the value of expr if it is Ok/Some, else fallback. modelled as its own node (not a BinOp) because it is faithful surface syntax with the loosest precedence, left-associative; a or b or c is (a or b) or c.

Fields

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

Interpolation

a string with {expr} interpolations – parts alternates literal text and embedded expressions, in source order. NOT desugared to a + chain; the conversion-and-concatenation happens in Phase 4 codegen.

Fields

§span: Span

Implementations§

Source§

impl Expr

Source

pub fn span(&self) -> Span

the source span of this expression.

every variant carries its span field; this match is exhaustive over all of them, which is the real guarantee that “every expression node has a span”. the parser computes each span from the first token to the last (via Span::to) when it builds the node.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

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 Expr

Source§

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

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

impl PartialEq for Expr

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more