Enum rustc_ast::ast::ExprKind[][src]

pub enum ExprKind {
Show 42 variants Box(P<Expr>), Array(Vec<P<Expr>>), ConstBlock(AnonConst), Call(P<Expr>, Vec<P<Expr>>), MethodCall(PathSegmentVec<P<Expr>>, Span), Tup(Vec<P<Expr>>), Binary(BinOpP<Expr>, P<Expr>), Unary(UnOpP<Expr>), Lit(Lit), Cast(P<Expr>, P<Ty>), Type(P<Expr>, P<Ty>), Let(P<Pat>, P<Expr>, Span), If(P<Expr>, P<Block>, Option<P<Expr>>), While(P<Expr>, P<Block>, Option<Label>), ForLoop(P<Pat>, P<Expr>, P<Block>, Option<Label>), Loop(P<Block>, Option<Label>), Match(P<Expr>, Vec<Arm>), Closure(CaptureByAsyncMovabilityP<FnDecl>, P<Expr>, Span), Block(P<Block>, Option<Label>), Async(CaptureByNodeIdP<Block>), Await(P<Expr>), TryBlock(P<Block>), Assign(P<Expr>, P<Expr>, Span), AssignOp(BinOpP<Expr>, P<Expr>), Field(P<Expr>, Ident), Index(P<Expr>, P<Expr>), Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits), Underscore, Path(Option<QSelf>, Path), AddrOf(BorrowKindMutabilityP<Expr>), Break(Option<Label>, Option<P<Expr>>), Continue(Option<Label>), Ret(Option<P<Expr>>), InlineAsm(P<InlineAsm>), LlvmInlineAsm(P<LlvmInlineAsm>), MacCall(MacCall), Struct(P<StructExpr>), Repeat(P<Expr>, AnonConst), Paren(P<Expr>), Try(P<Expr>), Yield(Option<P<Expr>>), Err,



A box x expression.

Tuple Fields of Box

0: P<Expr>

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

Tuple Fields of Array

0: Vec<P<Expr>>

Allow anonymous constants from an inline const block

Tuple Fields of ConstBlock

0: AnonConst
Call(P<Expr>, Vec<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.

Tuple Fields of Call

0: P<Expr>1: Vec<P<Expr>>
MethodCall(PathSegmentVec<P<Expr>>, Span)

A method call (x.foo::<'static, Bar, Baz>(a, b, c, d))

The PathSegment represents the method name and its generic arguments (within the angle brackets). The first element of the vector of an Expr is the expression that evaluates to the object on which the method is being called on (the receiver), and the remaining elements are the rest of the arguments. Thus, x.foo::<Bar, Baz>(a, b, c, d) is represented as ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d]). This Span is the span of the function, without the dot and receiver (e.g. foo(a, b) in x.foo(a, b)

Tuple Fields of MethodCall

0: PathSegment1: Vec<P<Expr>>2: Span

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

Tuple Fields of Tup

0: Vec<P<Expr>>
Binary(BinOpP<Expr>, P<Expr>)

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

Tuple Fields of Binary

0: BinOp1: P<Expr>2: P<Expr>

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

Tuple Fields of Unary

0: UnOp1: P<Expr>

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

Tuple Fields of Lit

0: Lit
Cast(P<Expr>, P<Ty>)

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

Tuple Fields of Cast

0: P<Expr>1: P<Ty>
Type(P<Expr>, P<Ty>)

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

Tuple Fields of Type

0: P<Expr>1: P<Ty>
Let(P<Pat>, P<Expr>, Span)

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.

Tuple Fields of Let

0: P<Pat>1: P<Expr>2: Span
If(P<Expr>, P<Block>, Option<P<Expr>>)

An if block, with an optional else block.

if expr { block } else { expr }

Tuple Fields of If

0: P<Expr>1: P<Block>2: Option<P<Expr>>
While(P<Expr>, P<Block>, Option<Label>)

A while loop, with an optional label.

'label: while expr { block }

Tuple Fields of While

0: P<Expr>1: P<Block>2: Option<Label>
ForLoop(P<Pat>, P<Expr>, P<Block>, Option<Label>)

A for loop, with an optional label.

'label: for pat in expr { block }

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

Tuple Fields of ForLoop

0: P<Pat>1: P<Expr>2: P<Block>3: Option<Label>
Loop(P<Block>, Option<Label>)

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

'label: loop { block }

Tuple Fields of Loop

0: P<Block>1: Option<Label>
Match(P<Expr>, Vec<Arm>)

A match block.

Tuple Fields of Match

0: P<Expr>1: Vec<Arm>
Closure(CaptureByAsyncMovabilityP<FnDecl>, P<Expr>, Span)

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

The final span is the span of the argument block |...|.

Tuple Fields of Closure

0: CaptureBy1: Async2: Movability3: P<FnDecl>4: P<Expr>5: Span
Block(P<Block>, Option<Label>)

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

Tuple Fields of Block

0: P<Block>1: Option<Label>

An async block (async move { ... }).

The NodeId is the NodeId for the closure that results from desugaring an async block, just like the NodeId field in the Async::Yes variant. This is necessary in order to create a def for the closure which can be used as a parent of any child defs. Defs created during lowering cannot be made the parent of any other preexisting defs.

Tuple Fields of Async

0: CaptureBy1: NodeId2: P<Block>

An await expression (my_future.await).

Tuple Fields of Await

0: P<Expr>

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

Tuple Fields of TryBlock

0: P<Block>
Assign(P<Expr>, P<Expr>, Span)

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

Tuple Fields of Assign

0: P<Expr>1: P<Expr>2: Span
AssignOp(BinOpP<Expr>, P<Expr>)

An assignment with an operator.

E.g., a += 1.

Tuple Fields of AssignOp

0: BinOp1: P<Expr>2: P<Expr>
Field(P<Expr>, Ident)

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

Tuple Fields of Field

0: P<Expr>1: Ident
Index(P<Expr>, P<Expr>)

An indexing operation (e.g., foo[2]).

Tuple Fields of Index

0: P<Expr>1: P<Expr>
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits)

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

Tuple Fields of Range

0: Option<P<Expr>>1: Option<P<Expr>>2: RangeLimits

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

Path(Option<QSelf>, Path)

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

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

Tuple Fields of Path

0: Option<QSelf>1: Path

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

Tuple Fields of AddrOf

0: BorrowKind1: Mutability2: P<Expr>
Break(Option<Label>, Option<P<Expr>>)

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

Tuple Fields of Break

0: Option<Label>1: Option<P<Expr>>

A continue, with an optional label.

Tuple Fields of Continue

0: Option<Label>

A return, with an optional value to be returned.

Tuple Fields of Ret

0: Option<P<Expr>>

Output of the asm!() macro.

Tuple Fields of InlineAsm

0: P<InlineAsm>

Output of the llvm_asm!() macro.

Tuple Fields of LlvmInlineAsm

0: P<LlvmInlineAsm>

A macro invocation; pre-expansion.

Tuple Fields of MacCall

0: MacCall

A struct literal expression.

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

Tuple Fields of Struct

0: P<StructExpr>
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.

Tuple Fields of Repeat

0: P<Expr>1: AnonConst

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

Tuple Fields of Paren

0: P<Expr>

A try expression (expr?).

Tuple Fields of Try

0: P<Expr>

A yield, with an optional value to be yielded.

Tuple Fields of Yield

0: Option<P<Expr>>

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.


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: 72 bytes

Size for each variant: