Enum rustc_hir::hir::ExprKind[][src]

pub enum ExprKind<'hir> {
Show 33 variants Box(&'hir Expr<'hir>), ConstBlock(AnonConst), Array(&'hir [Expr<'hir>]), Call(&'hir Expr<'hir>, &'hir [Expr<'hir>]), MethodCall(&'hir PathSegment<'hir>, Span&'hir [Expr<'hir>]Span), Tup(&'hir [Expr<'hir>]), Binary(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>), Unary(UnOp, &'hir Expr<'hir>), Lit(Lit), Cast(&'hir Expr<'hir>, &'hir Ty<'hir>), Type(&'hir Expr<'hir>, &'hir Ty<'hir>), DropTemps(&'hir Expr<'hir>), Let(&'hir Pat<'hir>, &'hir Expr<'hir>, Span), If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>), Loop(&'hir Block<'hir>, Option<Label>, LoopSourceSpan), Match(&'hir Expr<'hir>, &'hir [Arm<'hir>]MatchSource), Closure(CaptureBy, &'hir FnDecl<'hir>, BodyIdSpanOption<Movability>), Block(&'hir Block<'hir>, Option<Label>), Assign(&'hir Expr<'hir>, &'hir Expr<'hir>, Span), AssignOp(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>), Field(&'hir Expr<'hir>, Ident), Index(&'hir Expr<'hir>, &'hir Expr<'hir>), Path(QPath<'hir>), AddrOf(BorrowKindMutability, &'hir Expr<'hir>), Break(DestinationOption<&'hir Expr<'hir>>), Continue(Destination), Ret(Option<&'hir Expr<'hir>>), InlineAsm(&'hir InlineAsm<'hir>), LlvmInlineAsm(&'hir LlvmInlineAsm<'hir>), Struct(&'hir QPath<'hir>, &'hir [ExprField<'hir>]Option<&'hir Expr<'hir>>), Repeat(&'hir Expr<'hir>, AnonConst), Yield(&'hir Expr<'hir>, YieldSource), Err,
}

Variants

Box(&'hir Expr<'hir>)

A box x expression.

Tuple Fields of Box

0: &'hir Expr<'hir>
ConstBlock(AnonConst)

Allow anonymous constants from an inline const block

Tuple Fields of ConstBlock

0: AnonConst
Array(&'hir [Expr<'hir>])

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

Tuple Fields of Array

0: &'hir [Expr<'hir>]
Call(&'hir Expr<'hir>, &'hir [Expr<'hir>])

A function call.

The first field resolves to the function itself (usually an ExprKind::Path), 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: &'hir Expr<'hir>1: &'hir [Expr<'hir>]
MethodCall(&'hir PathSegment<'hir>, Span&'hir [Expr<'hir>]Span)

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

The PathSegment/Span represent the method name and its generic arguments (within the angle brackets). The first element of the vector of Exprs 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]). The final Span represents the span of the function and arguments (e.g. foo::<Bar, Baz>(a, b, c, d) in x.foo::<Bar, Baz>(a, b, c, d)

To resolve the called method to a DefId, call type_dependent_def_id with the hir_id of the MethodCall node itself.

Tuple Fields of MethodCall

0: &'hir PathSegment<'hir>1: Span2: &'hir [Expr<'hir>]3: Span
Tup(&'hir [Expr<'hir>])

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

Tuple Fields of Tup

0: &'hir [Expr<'hir>]
Binary(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>)

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

Tuple Fields of Binary

0: BinOp1: &'hir Expr<'hir>2: &'hir Expr<'hir>
Unary(UnOp, &'hir Expr<'hir>)

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

Tuple Fields of Unary

0: UnOp1: &'hir Expr<'hir>
Lit(Lit)

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

Tuple Fields of Lit

0: Lit
Cast(&'hir Expr<'hir>, &'hir Ty<'hir>)

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

Tuple Fields of Cast

0: &'hir Expr<'hir>1: &'hir Ty<'hir>
Type(&'hir Expr<'hir>, &'hir Ty<'hir>)

A type reference (e.g., Foo).

Tuple Fields of Type

0: &'hir Expr<'hir>1: &'hir Ty<'hir>
DropTemps(&'hir Expr<'hir>)

Wraps the expression in a terminating scope. This makes it semantically equivalent to { let _t = expr; _t }.

This construct only exists to tweak the drop order in HIR lowering. An example of that is the desugaring of for loops.

Tuple Fields of DropTemps

0: &'hir Expr<'hir>
Let(&'hir Pat<'hir>, &'hir Expr<'hir>, Span)

A let $pat = $expr expression.

These are not Local and only occur as expressions. The let Some(x) = foo() in if let Some(x) = foo() is an example of Let(..).

Tuple Fields of Let

0: &'hir Pat<'hir>1: &'hir Expr<'hir>2: Span
If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>)

An if block, with an optional else block.

I.e., if <expr> { <expr> } else { <expr> }.

Tuple Fields of If

0: &'hir Expr<'hir>1: &'hir Expr<'hir>2: Option<&'hir Expr<'hir>>
Loop(&'hir Block<'hir>, Option<Label>, LoopSourceSpan)

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

I.e., 'label: loop { <block> }.

The Span is the loop header (for x in y/while let pat = expr).

Tuple Fields of Loop

0: &'hir Block<'hir>1: Option<Label>2: LoopSource3: Span
Match(&'hir Expr<'hir>, &'hir [Arm<'hir>]MatchSource)

A match block, with a source that indicates whether or not it is the result of a desugaring, and if so, which kind.

Tuple Fields of Match

0: &'hir Expr<'hir>1: &'hir [Arm<'hir>]2: MatchSource
Closure(CaptureBy, &'hir FnDecl<'hir>, BodyIdSpanOption<Movability>)

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

The Span is the argument block |...|.

This may also be a generator literal or an async block as indicated by the Option<Movability>.

Tuple Fields of Closure

0: CaptureBy1: &'hir FnDecl<'hir>2: BodyId3: Span4: Option<Movability>
Block(&'hir Block<'hir>, Option<Label>)

A block (e.g., 'label: { ... }).

Tuple Fields of Block

0: &'hir Block<'hir>1: Option<Label>
Assign(&'hir Expr<'hir>, &'hir Expr<'hir>, Span)

An assignment (e.g., a = foo()).

Tuple Fields of Assign

0: &'hir Expr<'hir>1: &'hir Expr<'hir>2: Span
AssignOp(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>)

An assignment with an operator.

E.g., a += 1.

Tuple Fields of AssignOp

0: BinOp1: &'hir Expr<'hir>2: &'hir Expr<'hir>
Field(&'hir Expr<'hir>, Ident)

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

Tuple Fields of Field

0: &'hir Expr<'hir>1: Ident
Index(&'hir Expr<'hir>, &'hir Expr<'hir>)

An indexing operation (foo[2]).

Tuple Fields of Index

0: &'hir Expr<'hir>1: &'hir Expr<'hir>
Path(QPath<'hir>)

Path to a definition, possibly containing lifetime or type parameters.

Tuple Fields of Path

0: QPath<'hir>
AddrOf(BorrowKindMutability, &'hir Expr<'hir>)

A referencing operation (i.e., &a or &mut a).

Tuple Fields of AddrOf

0: BorrowKind1: Mutability2: &'hir Expr<'hir>
Break(DestinationOption<&'hir Expr<'hir>>)

A break, with an optional label to break.

Tuple Fields of Break

0: Destination1: Option<&'hir Expr<'hir>>
Continue(Destination)

A continue, with an optional label.

Tuple Fields of Continue

0: Destination
Ret(Option<&'hir Expr<'hir>>)

A return, with an optional value to be returned.

Tuple Fields of Ret

0: Option<&'hir Expr<'hir>>
InlineAsm(&'hir InlineAsm<'hir>)

Inline assembly (from asm!), with its outputs and inputs.

Tuple Fields of InlineAsm

0: &'hir InlineAsm<'hir>
LlvmInlineAsm(&'hir LlvmInlineAsm<'hir>)

Inline assembly (from llvm_asm!), with its outputs and inputs.

Tuple Fields of LlvmInlineAsm

0: &'hir LlvmInlineAsm<'hir>
Struct(&'hir QPath<'hir>, &'hir [ExprField<'hir>]Option<&'hir Expr<'hir>>)

A struct or struct-like variant literal expression.

E.g., Foo {x: 1, y: 2}, or Foo {x: 1, .. base}, where base is the Option<Expr>.

Tuple Fields of Struct

0: &'hir QPath<'hir>1: &'hir [ExprField<'hir>]2: Option<&'hir Expr<'hir>>
Repeat(&'hir Expr<'hir>, AnonConst)

An array literal constructed from one repeated element.

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

Tuple Fields of Repeat

0: &'hir Expr<'hir>1: AnonConst
Yield(&'hir Expr<'hir>, YieldSource)

A suspension point for generators (i.e., yield <expr>).

Tuple Fields of Yield

0: &'hir Expr<'hir>1: YieldSource
Err

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

Trait Implementations

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

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

Size for each variant: