Skip to main content

## ExprKind

# Enum ExprKind

Source

    pub enum ExprKind {
    Show 49 variants    Array(ThinVec<Box<Expr>>),
        ConstBlock(AnonConst),
        Call(Box<Expr>, ThinVec<Box<Expr>>),
        MethodCall(Box<MethodCall>),
        Tup(ThinVec<Box<Expr>>),
        Binary(BinOp, Box<Expr>, Box<Expr>),
        Unary(UnOp, Box<Expr>),
        Move(Box<Expr>, Span),
        Lit(Lit),
        Cast(Box<Expr>, Box<Ty>),
        Type(Box<Expr>, Box<Ty>),
        Let(Box<Pat>, Box<Expr>, Span, Recovered),
        If(Box<Expr>, Box<Block>, Option<Box<Expr>>),
        While(Box<Expr>, Box<Block>, Option<Label>),
        ForLoop {
            pat: Box<Pat>,
            iter: Box<Expr>,
            body: Box<Block>,
            label: Option<Label>,
            kind: ForLoopKind,
        },
        Loop(Box<Block>, Option<Label>, Span),
        Match(Box<Expr>, ThinVec<Arm>, MatchKind),
        Closure(Box<Closure>),
        Block(Box<Block>, Option<Label>),
        Gen(CaptureBy, Box<Block>, GenBlockKind, Span),
        Await(Box<Expr>, Span),
        Use(Box<Expr>, Span),
        TryBlock(Box<Block>, Option<Box<Ty>>),
        Assign(Box<Expr>, Box<Expr>, Span),
        AssignOp(AssignOp, Box<Expr>, Box<Expr>),
        Field(Box<Expr>, Ident),
        Index(Box<Expr>, Box<Expr>, Span),
        Range(Option<Box<Expr>>, Option<Box<Expr>>, RangeLimits),
        Underscore,
        Path(Option<Box<QSelf>>, Path),
        AddrOf(BorrowKind, Mutability, Box<Expr>),
        Break(Option<Label>, Option<Box<Expr>>),
        Continue(Option<Label>),
        Ret(Option<Box<Expr>>),
        InlineAsm(Box<InlineAsm>),
        OffsetOf(Box<Ty>, Vec<Ident>),
        MacCall(Box<MacCall>),
        Struct(Box<StructExpr>),
        Repeat(Box<Expr>, AnonConst),
        Paren(Box<Expr>),
        Try(Box<Expr>),
        Yield(YieldKind),
        Yeet(Option<Box<Expr>>),
        Become(Box<Expr>),
        IncludedBytes(ByteSymbol),
        FormatArgs(Box<FormatArgs>),
        UnsafeBinderCast(UnsafeBinderCastKind, Box<Expr>, Option<Box<Ty>>),
        Err(ErrorGuaranteed),
        Dummy,
    }

## Variants§

§

### Array(ThinVec<Box<Expr>>)

An array (e.g, `[a, b, c, d]`).

§

### ConstBlock(AnonConst)

Allow anonymous constants from an inline `const` block.

§

### Call(Box<Expr>, ThinVec<Box<Expr>>)

A function call.

The first field resolves to the function itself, and the second field is the list of arguments. This also represents calling the constructor of tuple-like ADTs such as tuple structs and enum variants.

§

### MethodCall(Box<MethodCall>)

A method call (e.g., `x.foo::<Bar, Baz>(a, b, c)`).

§

### Tup(ThinVec<Box<Expr>>)

A tuple (e.g., `(a, b, c, d)`).

§

### Binary(BinOp, Box<Expr>, Box<Expr>)

A binary operation (e.g., `a + b`, `a * b`).

§

### Unary(UnOp, Box<Expr>)

A unary operation (e.g., `!x`, `*x`).

§

### Move(Box<Expr>, Span)

A `move(expr)` expression.

§

### Lit(Lit)

A literal (e.g., `1`, `"foo"`).

§

### Cast(Box<Expr>, Box<Ty>)

A cast (e.g., `foo as f64`).

§

### Type(Box<Expr>, Box<Ty>)

A type ascription (e.g., `builtin # type_ascribe(42, usize)`).

Usually not written directly in user code but indirectly via the macro `type_ascribe!(...)`.

§

### Let(Box<Pat>, Box<Expr>, Span, Recovered)

A `let pat = expr` expression that is only semantically allowed in the condition of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`).

`Span` represents the whole `let pat = expr` statement.

§

### If(Box<Expr>, Box<Block>, Option<Box<Expr>>)

An `if` block, with an optional `else` block.

`if expr { block } else { expr }`

If present, the “else” expr is always `ExprKind::Block` (for `else`) or `ExprKind::If` (for `else if`).

§

### While(Box<Expr>, Box<Block>, Option<Label>)

A while loop, with an optional label.

`'label: while expr { block }`

§

### ForLoop

A `for` loop, with an optional label.

`'label: for await? pat in iter { block }`

This is desugared to a combination of `loop` and `match` expressions.

#### Fields

§`pat: Box<Pat>`
§`iter: Box<Expr>`
§`body: Box<Block>`
§`label: Option<Label>`
§`kind: ForLoopKind`
§

### Loop(Box<Block>, Option<Label>, Span)

Conditionless loop (can be exited with `break`, `continue`, or `return`).

`'label: loop { block }`

§

### Match(Box<Expr>, ThinVec<Arm>, MatchKind)

A `match` block.

§

### Closure(Box<Closure>)

A closure (e.g., `move |a, b, c| a + b + c`).

§

### Block(Box<Block>, Option<Label>)

A block (`'label: { ... }`).

§

### Gen(CaptureBy, Box<Block>, GenBlockKind, Span)

An `async` block (`async move { ... }`), or a `gen` block (`gen move { ... }`).

The span is the “decl”, which is the header before the body `{ }` including the `async`/`gen` keywords and possibly `move`.

§

### Await(Box<Expr>, Span)

An await expression (`my_future.await`). Span is of await keyword.

§

### Use(Box<Expr>, Span)

A use expression (`x.use`). Span is of use keyword.

§

### TryBlock(Box<Block>, Option<Box<Ty>>)

A try block (`try { ... }`), if the type is `None`, or A try block (`try bikeshed Ty { ... }`) if the type is `Some`.

Note that `try bikeshed` is a deliberately ridiculous placeholder syntax to avoid deciding what keyword or symbol should go there. It’s that way for experimentation only; an RFC to decide the final semantics and syntax would be needed to put it on stabilization-track.

§

### Assign(Box<Expr>, Box<Expr>, Span)

An assignment (`a = foo()`). The `Span` argument is the span of the `=` token.

§

### AssignOp(AssignOp, Box<Expr>, Box<Expr>)

An assignment with an operator.

E.g., `a += 1`.

§

### Field(Box<Expr>, Ident)

Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.

§

### Index(Box<Expr>, Box<Expr>, Span)

An indexing operation (e.g., `foo[2]`). The span represents the span of the `[2]`, including brackets.

§

### Range(Option<Box<Expr>>, Option<Box<Expr>>, RangeLimits)

A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`; and `..` in destructuring assignment).

§

### Underscore

An underscore, used in destructuring assignment to ignore a value.

§

### Path(Option<Box<QSelf>>, Path)

Variable reference, possibly containing `::` and/or type parameters (e.g., `foo::bar::<baz>`).

Optionally “qualified” (e.g., `<Vec<T> as SomeTrait>::SomeType`).

§

### AddrOf(BorrowKind, Mutability, Box<Expr>)

A referencing operation (`&a`, `&mut a`, `&raw const a` or `&raw mut a`).

§

### Break(Option<Label>, Option<Box<Expr>>)

A `break`, with an optional label to break, and an optional expression.

§

### Continue(Option<Label>)

A `continue`, with an optional label.

§

### Ret(Option<Box<Expr>>)

A `return`, with an optional value to be returned.

§

### InlineAsm(Box<InlineAsm>)

Output of the `asm!()` macro.

§

### OffsetOf(Box<Ty>, Vec<Ident>)

An `offset_of` expression (e.g., `builtin # offset_of(Struct, field)`).

Usually not written directly in user code but indirectly via the macro `core::mem::offset_of!(...)`.

§

### MacCall(Box<MacCall>)

A macro invocation; pre-expansion.

§

### Struct(Box<StructExpr>)

A struct literal expression.

E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. rest}`.

§

### Repeat(Box<Expr>, AnonConst)

An array literal constructed from one repeated element.

E.g., `[1; 5]`. The expression is the element to be repeated; the constant is the number of times to repeat it.

§

### Paren(Box<Expr>)

No-op: used solely so we can pretty-print faithfully.

§

### Try(Box<Expr>)

A try expression (`expr?`).

§

### Yield(YieldKind)

A `yield`, with an optional value to be yielded.

§

### Yeet(Option<Box<Expr>>)

A `do yeet` (aka `throw`/`fail`/`bail`/`raise`/whatever), with an optional value to be returned.

§

### Become(Box<Expr>)

A tail call return, with the value to be returned.

While `.0` must be a function call, we check this later, after parsing.

§

### IncludedBytes(ByteSymbol)

Bytes included via `include_bytes!`

Added for optimization purposes to avoid the need to escape large binary blobs - should always behave like `ExprKind::Lit` with a `ByteStr` literal.

The value is stored as a `ByteSymbol`. It’s unfortunate that we need to intern (hash) the bytes because they’re likely to be large and unique. But it’s necessary because this will eventually be lowered to `LitKind::ByteStr`, which needs a `ByteSymbol` to impl `Copy` and avoid arena allocation.

§

### FormatArgs(Box<FormatArgs>)

A `format_args!()` expression.

§

### UnsafeBinderCast(UnsafeBinderCastKind, Box<Expr>, Option<Box<Ty>>)

§

### Err(ErrorGuaranteed)

Placeholder for an expression that wasn’t syntactically well formed in some way.

§

### Dummy

Acts as a null expression. Lowering it will always emit a bug.

## Trait Implementations§

Source§

### impl Clone for ExprKind

Source§

#### fn clone(&self) -> ExprKind

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<__D: SpanDecoder> Decodable<__D> for ExprKind

Source§

#### fn decode(__decoder: &mut __D) -> Self

Source§

### impl<__E: SpanEncoder> Encodable<__E> for ExprKind

Source§

#### fn encode(&self, __encoder: &mut __E)

## Auto Trait Implementations§

§

### impl DynSend for ExprKind

§

### impl DynSync for ExprKind

§

### impl Freeze for ExprKind

§

### impl RefUnwindSafe for ExprKind

§

### impl Send for ExprKind

§

### impl Sync for ExprKind

§

### impl Unpin for ExprKind

§

### impl UnsafeUnpin for ExprKind

§

### impl UnwindSafe for ExprKind

## Blanket Implementations§

Source§

### impl<T> Aligned for T

Source§

#### const ALIGN: Alignment

Alignment of `Self`.
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> Instrument for T

Source§

#### fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided `Span`, returning an `Instrumented` wrapper. Read more
Source§

#### fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more
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> IntoEither for T

Source§

#### fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts `self` into a `Left` variant of `Either<Self, Self>` if `into_left` is `true`. Converts `self` into a `Right` variant of `Either<Self, Self>` otherwise. Read more
Source§

#### fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts `self` into a `Left` variant of `Either<Self, Self>` if `into_left(&self)` returns `true`. Converts `self` into a `Right` variant of `Either<Self, Self>` otherwise. Read more
Source§

### impl<T> MutVisitorResult for T

Source§

#### type Result = ()

Source§

### impl<T> Pointable for T

Source§

#### const ALIGN: usize

The alignment of pointer.
Source§

#### type Init = T

The type for initializers.
Source§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

### impl<T> Same for T

Source§

#### type Output = T

Should always be `Self`
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<T> WithSubscriber for T

Source§

#### fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more
Source§

#### fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Read more

## Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain `repr(...)` attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 40 bytes

Size for each variant:

- `Array`: 15 bytes
- `ConstBlock`: 23 bytes
- `Call`: 23 bytes
- `MethodCall`: 15 bytes
- `Tup`: 15 bytes
- `Binary`: 31 bytes
- `Unary`: 15 bytes
- `Move`: 23 bytes
- `Lit`: 15 bytes
- `Cast`: 23 bytes
- `Type`: 23 bytes
- `Let`: 31 bytes
- `If`: 31 bytes
- `While`: 31 bytes
- `ForLoop`: 39 bytes
- `Loop`: 31 bytes
- `Match`: 23 bytes
- `Closure`: 15 bytes
- `Block`: 23 bytes
- `Gen`: 31 bytes
- `Await`: 23 bytes
- `Use`: 23 bytes
- `TryBlock`: 23 bytes
- `Assign`: 31 bytes
- `AssignOp`: 31 bytes
- `Field`: 23 bytes
- `Index`: 31 bytes
- `Range`: 23 bytes
- `Underscore`: 0 bytes
- `Path`: 39 bytes
- `AddrOf`: 15 bytes
- `Break`: 23 bytes
- `Continue`: 15 bytes
- `Ret`: 15 bytes
- `InlineAsm`: 15 bytes
- `OffsetOf`: 39 bytes
- `MacCall`: 15 bytes
- `Struct`: 15 bytes
- `Repeat`: 31 bytes
- `Paren`: 15 bytes
- `Try`: 15 bytes
- `Yield`: 23 bytes
- `Yeet`: 15 bytes
- `Become`: 15 bytes
- `IncludedBytes`: 7 bytes
- `FormatArgs`: 15 bytes
- `UnsafeBinderCast`: 23 bytes
- `Err`: 0 bytes
- `Dummy`: 0 bytes