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

pub enum ExprKind<'hir> {
Show 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>), If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>), Loop(&'hir Block<'hir>, Option<Label>, LoopSource, Span), Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource), Closure(CaptureBy, &'hir FnDecl<'hir>, BodyId, Span, Option<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(BorrowKind, Mutability, &'hir Expr<'hir>), Break(Destination, Option<&'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>)
Expand description

A box x expression.

ConstBlock(AnonConst)
Expand description

Allow anonymous constants from an inline const block

Array(&'hir [Expr<'hir>])
Expand description

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

Call(&'hir Expr<'hir>, &'hir [Expr<'hir>])
Expand description

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.

MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>], Span)
Expand description

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.

Tup(&'hir [Expr<'hir>])
Expand description

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

Binary(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>)
Expand description

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

Unary(UnOp, &'hir Expr<'hir>)
Expand description

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

Lit(Lit)
Expand description

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

Cast(&'hir Expr<'hir>, &'hir Ty<'hir>)
Expand description

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

Type(&'hir Expr<'hir>, &'hir Ty<'hir>)
Expand description

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

DropTemps(&'hir Expr<'hir>)
Expand description

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.

If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>)
Expand description

An if block, with an optional else block.

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

Loop(&'hir Block<'hir>, Option<Label>, LoopSource, Span)
Expand description

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

Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource)
Expand description

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

Closure(CaptureBy, &'hir FnDecl<'hir>, BodyId, Span, Option<Movability>)
Expand description

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

Block(&'hir Block<'hir>, Option<Label>)
Expand description

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

Assign(&'hir Expr<'hir>, &'hir Expr<'hir>, Span)
Expand description

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

AssignOp(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>)
Expand description

An assignment with an operator.

E.g., a += 1.

Field(&'hir Expr<'hir>, Ident)
Expand description

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

Index(&'hir Expr<'hir>, &'hir Expr<'hir>)
Expand description

An indexing operation (foo[2]).

Path(QPath<'hir>)
Expand description

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

AddrOf(BorrowKind, Mutability, &'hir Expr<'hir>)
Expand description

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

Break(Destination, Option<&'hir Expr<'hir>>)
Expand description

A break, with an optional label to break.

Continue(Destination)
Expand description

A continue, with an optional label.

Ret(Option<&'hir Expr<'hir>>)
Expand description

A return, with an optional value to be returned.

InlineAsm(&'hir InlineAsm<'hir>)
Expand description

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

LlvmInlineAsm(&'hir LlvmInlineAsm<'hir>)
Expand description

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

Struct(&'hir QPath<'hir>, &'hir [ExprField<'hir>], Option<&'hir Expr<'hir>>)
Expand description

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

Repeat(&'hir Expr<'hir>, AnonConst)
Expand description

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.

Yield(&'hir Expr<'hir>, YieldSource)
Expand description

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

Err
Expand description

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

Trait Implementations

impl<'hir> Debug for ExprKind<'hir>[src]

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

Formats the value using the given formatter. Read more

impl<'hir, __CTX> HashStable<__CTX> for ExprKind<'hir> where
    __CTX: HashStableContext, 
[src]

fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)[src]

Auto Trait Implementations

impl<'hir> !RefUnwindSafe for ExprKind<'hir>

impl<'hir> !Send for ExprKind<'hir>

impl<'hir> !Sync for ExprKind<'hir>

impl<'hir> Unpin for ExprKind<'hir>

impl<'hir> !UnwindSafe for ExprKind<'hir>

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.