Enum rustc_middle::thir::ExprKind
source · pub enum ExprKind<'tcx> {
Show 46 variants
Scope {
region_scope: Scope,
lint_level: LintLevel,
value: ExprId,
},
Box {
value: ExprId,
},
If {
if_then_scope: Scope,
cond: ExprId,
then: ExprId,
else_opt: Option<ExprId>,
},
Call {
ty: Ty<'tcx>,
fun: ExprId,
args: Box<[ExprId]>,
from_hir_call: bool,
fn_span: Span,
},
Deref {
arg: ExprId,
},
Binary {
op: BinOp,
lhs: ExprId,
rhs: ExprId,
},
LogicalOp {
op: LogicalOp,
lhs: ExprId,
rhs: ExprId,
},
Unary {
op: UnOp,
arg: ExprId,
},
Cast {
source: ExprId,
},
Use {
source: ExprId,
},
NeverToAny {
source: ExprId,
},
PointerCoercion {
cast: PointerCoercion,
source: ExprId,
},
Loop {
body: ExprId,
},
Let {
expr: ExprId,
pat: Box<Pat<'tcx>>,
},
Match {
scrutinee: ExprId,
scrutinee_hir_id: HirId,
arms: Box<[ArmId]>,
match_source: MatchSource,
},
Block {
block: BlockId,
},
Assign {
lhs: ExprId,
rhs: ExprId,
},
AssignOp {
op: BinOp,
lhs: ExprId,
rhs: ExprId,
},
Field {
lhs: ExprId,
variant_index: VariantIdx,
name: FieldIdx,
},
Index {
lhs: ExprId,
index: ExprId,
},
VarRef {
id: LocalVarId,
},
UpvarRef {
closure_def_id: DefId,
var_hir_id: LocalVarId,
},
Borrow {
borrow_kind: BorrowKind,
arg: ExprId,
},
AddressOf {
mutability: Mutability,
arg: ExprId,
},
Break {
label: Scope,
value: Option<ExprId>,
},
Continue {
label: Scope,
},
Return {
value: Option<ExprId>,
},
Become {
value: ExprId,
},
ConstBlock {
did: DefId,
args: GenericArgsRef<'tcx>,
},
Repeat {
value: ExprId,
count: Const<'tcx>,
},
Array {
fields: Box<[ExprId]>,
},
Tuple {
fields: Box<[ExprId]>,
},
Adt(Box<AdtExpr<'tcx>>),
PlaceTypeAscription {
source: ExprId,
user_ty: Option<Box<CanonicalUserType<'tcx>>>,
},
ValueTypeAscription {
source: ExprId,
user_ty: Option<Box<CanonicalUserType<'tcx>>>,
},
Closure(Box<ClosureExpr<'tcx>>),
Literal {
lit: &'tcx Lit,
neg: bool,
},
NonHirLiteral {
lit: ScalarInt,
user_ty: Option<Box<CanonicalUserType<'tcx>>>,
},
ZstLiteral {
user_ty: Option<Box<CanonicalUserType<'tcx>>>,
},
NamedConst {
def_id: DefId,
args: GenericArgsRef<'tcx>,
user_ty: Option<Box<CanonicalUserType<'tcx>>>,
},
ConstParam {
param: ParamConst,
def_id: DefId,
},
StaticRef {
alloc_id: AllocId,
ty: Ty<'tcx>,
def_id: DefId,
},
InlineAsm(Box<InlineAsmExpr<'tcx>>),
OffsetOf {
container: Ty<'tcx>,
fields: &'tcx List<(VariantIdx, FieldIdx)>,
},
ThreadLocalRef(DefId),
Yield {
value: ExprId,
},
}
Variants§
Scope
Scope
s are used to explicitly mark destruction scopes,
and to track the HirId
of the expressions within the scope.
Box
A box <value>
expression.
If
An if
expression.
Call
A function call. Method calls and overloaded operators are converted to plain function calls.
Fields
args: Box<[ExprId]>
The arguments passed to the function.
Note: in some cases (like calling a closure), the function call f(...args)
gets
rewritten as a call to a function trait method (e.g. FnOnce::call_once(f, (...args))
).
Deref
A non-overloaded dereference.
Binary
A non-overloaded binary operation.
LogicalOp
A logical operation. This is distinct from BinaryOp
because
the operands need to be lazily evaluated.
Unary
A non-overloaded unary operation. Note that here the deref (*
)
operator is represented by ExprKind::Deref
.
Cast
A cast: <source> as <type>
. The type we cast to is the type of
the parent expression.
Use
Forces its contents to be treated as a value expression, not a place expression. This is inserted in some places where an operation would otherwise be erased completely (e.g. some no-op casts), but we still need to ensure that its operand is treated as a value and not a place.
NeverToAny
A coercion from !
to any type.
PointerCoercion
A pointer coercion. More information can be found in PointerCoercion
.
Pointer casts that cannot be done by coercions are represented by ExprKind::Cast
.
Loop
A loop
expression.
Let
Special expression representing the let
part of an if let
or similar construct
(including if let
guards in match arms, and let-chains formed by &&
).
This isn’t considered a real expression in surface Rust syntax, so it can
only appear in specific situations, such as within the condition of an if
.
(Not to be confused with StmtKind::Let
, which is a normal let
statement.)
Match
A match
expression.
Block
A block.
Assign
An assignment: lhs = rhs
.
AssignOp
A non-overloaded operation assignment, e.g. lhs += rhs
.
Field
Access to a field of a struct, a tuple, an union, or an enum.
Fields
variant_index: VariantIdx
Variant containing the field.
Index
A non-overloaded indexing operation.
VarRef
A local variable.
Fields
id: LocalVarId
UpvarRef
Used to represent upvars mentioned in a closure/coroutine
Fields
var_hir_id: LocalVarId
HirId of the root variable
Borrow
A borrow, e.g. &arg
.
AddressOf
A &raw [const|mut] $place_expr
raw borrow resulting in type *[const|mut] T
.
Break
A break
expression.
Continue
A continue
expression.
Return
A return
expression.
Become
A become
expression.
ConstBlock
An inline const
block, e.g. const {}
.
Repeat
An array literal constructed from one repeated element, e.g. [1; 5]
.
Array
An array, e.g. [a, b, c, d]
.
Tuple
A tuple, e.g. (a, b, c, d)
.
Adt(Box<AdtExpr<'tcx>>)
An ADT constructor, e.g. Foo {x: 1, y: 2}
.
PlaceTypeAscription
A type ascription on a place.
Fields
user_ty: Option<Box<CanonicalUserType<'tcx>>>
Type that the user gave to this expression
ValueTypeAscription
A type ascription on a value, e.g. 42: i32
.
Fields
user_ty: Option<Box<CanonicalUserType<'tcx>>>
Type that the user gave to this expression
Closure(Box<ClosureExpr<'tcx>>)
A closure definition.
Literal
A literal.
NonHirLiteral
For literals that don’t correspond to anything in the HIR
ZstLiteral
A literal of a ZST type.
Fields
user_ty: Option<Box<CanonicalUserType<'tcx>>>
NamedConst
Associated constants and named constants
ConstParam
StaticRef
A literal containing the address of a static
.
This is only distinguished from Literal
so that we can register some
info for diagnostics.
InlineAsm(Box<InlineAsmExpr<'tcx>>)
Inline assembly, i.e. asm!()
.
OffsetOf
Field offset (offset_of!
)
ThreadLocalRef(DefId)
An expression taking a reference to a thread local.
Yield
A yield
expression.
Trait Implementations§
source§impl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for ExprKind<'tcx>
impl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for ExprKind<'tcx>
fn hash_stable( &self, __hcx: &mut StableHashingContext<'__ctx>, __hasher: &mut StableHasher, )
Auto Trait Implementations§
impl<'tcx> DynSend for ExprKind<'tcx>
impl<'tcx> DynSync for ExprKind<'tcx>
impl<'tcx> Freeze for ExprKind<'tcx>
impl<'tcx> !RefUnwindSafe for ExprKind<'tcx>
impl<'tcx> Send for ExprKind<'tcx>
impl<'tcx> Sync for ExprKind<'tcx>
impl<'tcx> Unpin for ExprKind<'tcx>
impl<'tcx> !UnwindSafe for ExprKind<'tcx>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<Tcx, T> DepNodeParams<Tcx> for T
impl<Tcx, T> DepNodeParams<Tcx> for T
default fn fingerprint_style() -> FingerprintStyle
source§default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint
default fn to_debug_str(&self, _: Tcx) -> String
source§default fn recover(_: Tcx, _: &DepNode) -> Option<T>
default fn recover(_: Tcx, _: &DepNode) -> Option<T>
DepNode
,
something which is needed when forcing DepNode
s during red-green
evaluation. The query system will only call this method if
fingerprint_style()
is not FingerprintStyle::Opaque
.
It is always valid to return None
here, in which case incremental
compilation will treat the query as having changed instead of forcing it.source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
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: 40 bytes
Size for each variant:
Scope
: 23 bytesBox
: 7 bytesIf
: 23 bytesCall
: 39 bytesDeref
: 7 bytesBinary
: 11 bytesLogicalOp
: 11 bytesUnary
: 7 bytesCast
: 7 bytesUse
: 7 bytesNeverToAny
: 7 bytesPointerCoercion
: 7 bytesLoop
: 7 bytesLet
: 15 bytesMatch
: 39 bytesBlock
: 7 bytesAssign
: 11 bytesAssignOp
: 11 bytesField
: 15 bytesIndex
: 11 bytesVarRef
: 11 bytesUpvarRef
: 19 bytesBorrow
: 7 bytesAddressOf
: 7 bytesBreak
: 15 bytesContinue
: 11 bytesReturn
: 7 bytesBecome
: 7 bytesConstBlock
: 23 bytesRepeat
: 15 bytesArray
: 23 bytesTuple
: 23 bytesAdt
: 15 bytesPlaceTypeAscription
: 15 bytesValueTypeAscription
: 15 bytesClosure
: 15 bytesLiteral
: 15 bytesNonHirLiteral
: 31 bytesZstLiteral
: 15 bytesNamedConst
: 31 bytesConstParam
: 19 bytesStaticRef
: 31 bytesInlineAsm
: 15 bytesOffsetOf
: 23 bytesThreadLocalRef
: 11 bytesYield
: 7 bytes