rustc_hir::hir

Enum ExprKind

Source
pub enum ExprKind<'hir> {
Show 33 variants ConstBlock(ConstBlock), Array(&'hir [Expr<'hir>]), Call(&'hir Expr<'hir>, &'hir [Expr<'hir>]), MethodCall(&'hir PathSegment<'hir>, &'hir Expr<'hir>, &'hir [Expr<'hir>], Span), Tup(&'hir [Expr<'hir>]), Binary(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>), Unary(UnOp, &'hir Expr<'hir>), Lit(&'hir Lit), Cast(&'hir Expr<'hir>, &'hir Ty<'hir>), Type(&'hir Expr<'hir>, &'hir Ty<'hir>), DropTemps(&'hir Expr<'hir>), Let(&'hir LetExpr<'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(&'hir Closure<'hir>), 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>, Span), Path(QPath<'hir>), AddrOf(BorrowKind, Mutability, &'hir Expr<'hir>), Break(Destination, Option<&'hir Expr<'hir>>), Continue(Destination), Ret(Option<&'hir Expr<'hir>>), Become(&'hir Expr<'hir>), InlineAsm(&'hir InlineAsm<'hir>), OffsetOf(&'hir Ty<'hir>, &'hir [Ident]), Struct(&'hir QPath<'hir>, &'hir [ExprField<'hir>], Option<&'hir Expr<'hir>>), Repeat(&'hir Expr<'hir>, ArrayLen<'hir>), Yield(&'hir Expr<'hir>, YieldSource), Err(ErrorGuaranteed),
}

Variants§

§

ConstBlock(ConstBlock)

Allow anonymous constants from an inline const block

§

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

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

§

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.

§

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

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

The PathSegment represents the method name and its generic arguments (within the angle brackets). The &Expr is the expression that evaluates to the object on which the method is being called on (the receiver), and the &[Expr] is 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], span). 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>])

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

§

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

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

§

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

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

§

Lit(&'hir Lit)

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

§

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

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

§

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

A type ascription (e.g., x: Foo). See RFC 3307.

§

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 AST lowering. An example of that is the desugaring of for loops.

§

Let(&'hir LetExpr<'hir>)

A let $pat = $expr expression.

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

§

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

§

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

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)

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

§

Closure(&'hir Closure<'hir>)

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

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

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

§

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

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

§

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

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

§

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

An assignment with an operator.

E.g., a += 1.

§

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

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>, Span)

An indexing operation (foo[2]). Similar to ExprKind::MethodCall, the final Span represents the span of the brackets and index.

§

Path(QPath<'hir>)

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

§

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

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

§

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

A break, with an optional label to break.

§

Continue(Destination)

A continue, with an optional label.

§

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

A return, with an optional value to be returned.

§

Become(&'hir Expr<'hir>)

A become, with the value to be returned.

§

InlineAsm(&'hir InlineAsm<'hir>)

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

§

OffsetOf(&'hir Ty<'hir>, &'hir [Ident])

Field offset (offset_of!)

§

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

§

Repeat(&'hir Expr<'hir>, ArrayLen<'hir>)

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)

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

§

Err(ErrorGuaranteed)

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

Trait Implementations§

Source§

impl<'hir> Clone for ExprKind<'hir>

Source§

fn clone(&self) -> ExprKind<'hir>

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
Source§

impl<'hir> Debug for ExprKind<'hir>

Source§

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

Formats the value using the given formatter. Read more
Source§

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

Source§

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

Source§

impl<'hir> Copy for ExprKind<'hir>

Auto Trait Implementations§

§

impl<'hir> DynSend for ExprKind<'hir>

§

impl<'hir> DynSync for ExprKind<'hir>

§

impl<'hir> Freeze for ExprKind<'hir>

§

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§

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<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for T
where T: Copy,

Source§

fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T

Source§

fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

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

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:

  • ConstBlock: 23 bytes
  • Array: 23 bytes
  • Call: 31 bytes
  • MethodCall: 47 bytes
  • Tup: 23 bytes
  • Binary: 31 bytes
  • Unary: 15 bytes
  • Lit: 15 bytes
  • Cast: 23 bytes
  • Type: 23 bytes
  • DropTemps: 15 bytes
  • Let: 15 bytes
  • If: 31 bytes
  • Loop: 31 bytes
  • Match: 39 bytes
  • Closure: 15 bytes
  • Block: 23 bytes
  • Assign: 31 bytes
  • AssignOp: 31 bytes
  • Field: 23 bytes
  • Index: 31 bytes
  • Path: 31 bytes
  • AddrOf: 15 bytes
  • Break: 31 bytes
  • Continue: 23 bytes
  • Ret: 15 bytes
  • Become: 15 bytes
  • InlineAsm: 15 bytes
  • OffsetOf: 31 bytes
  • Struct: 39 bytes
  • Repeat: 31 bytes
  • Yield: 23 bytes
  • Err: 0 bytes