Enum rustc_ast::ast::ExprKind

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




An array ([a, b, c, d])



Allow anonymous constants from an inline const block


Call(P<Expr>, ThinVec<P<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.



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



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


Binary(BinOp, P<Expr>, P<Expr>)

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


Unary(UnOp, P<Expr>)

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



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


Cast(P<Expr>, P<Ty>)

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


Type(P<Expr>, P<Ty>)

A type ascription (e.g., 42: usize).


Let(P<Pat>, P<Expr>, Span, Option<ErrorGuaranteed>)

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(P<Expr>, P<Block>, Option<P<Expr>>)

An if block, with an optional else block.

if expr { block } else { expr }


While(P<Expr>, P<Block>, Option<Label>)

A while loop, with an optional label.

'label: while expr { block }



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.


§pat: P<Pat>
§iter: P<Expr>
§body: P<Block>
§label: Option<Label>

Loop(P<Block>, Option<Label>, Span)

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

'label: loop { block }


Match(P<Expr>, ThinVec<Arm>, MatchKind)

A match block.



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


Block(P<Block>, Option<Label>)

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


Gen(CaptureBy, P<Block>, GenBlockKind)

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


Await(P<Expr>, Span)

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



A try block (try { ... }).


Assign(P<Expr>, P<Expr>, Span)

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


AssignOp(BinOp, P<Expr>, P<Expr>)

An assignment with an operator.

E.g., a += 1.


Field(P<Expr>, Ident)

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


Index(P<Expr>, P<Expr>, Span)

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


Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits)

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



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


Path(Option<P<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, P<Expr>)

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


Break(Option<Label>, Option<P<Expr>>)

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



A continue, with an optional label.



A return, with an optional value to be returned.



Output of the asm!() macro.


OffsetOf(P<Ty>, P<[Ident]>)

Output of the offset_of!() macro.



A macro invocation; pre-expansion.



A struct literal expression.

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


Repeat(P<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.



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



A try expression (expr?).



A yield, with an optional value to be yielded.



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



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

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



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.



A format_args!() expression.



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



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

Trait Implementations§


impl Clone for ExprKind


fn clone(&self) -> ExprKind

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

impl Debug for ExprKind


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

Formats the value using the given formatter. Read more

impl<__D: SpanDecoder> Decodable<__D> for ExprKind


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


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


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

Auto Trait Implementations§

Blanket Implementations§


impl<T> Aligned for T


const ALIGN: Alignment = _

Alignment of Self.

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


fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more

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


fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

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


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

Mutably borrows from an owned value. Read more

impl<T> From<T> for T


fn from(t: T) -> T

Returns the argument unchanged.


impl<T> Instrument for T


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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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


fn into(self) -> U

Calls U::from(self).

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


impl<T> Same for T


type Output = T

Should always be Self

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


type Owned = T

The resulting type after obtaining ownership.

fn to_owned(&self) -> T

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

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

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

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


type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

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


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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> WithSubscriber for T


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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<'a, T> Captures<'a> for T
where T: ?Sized,


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
  • 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: 23 bytes
  • Await: 23 bytes
  • TryBlock: 15 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: 31 bytes
  • MacCall: 15 bytes
  • Struct: 15 bytes
  • Repeat: 31 bytes
  • Paren: 15 bytes
  • Try: 15 bytes
  • Yield: 15 bytes
  • Yeet: 15 bytes
  • Become: 15 bytes
  • IncludedBytes: 23 bytes
  • FormatArgs: 15 bytes
  • Err: 0 bytes
  • Dummy: 0 bytes