pub enum ExprKind {
Show 47 variants
Array(ThinVec<P<Expr>>),
ConstBlock(AnonConst),
Call(P<Expr>, ThinVec<P<Expr>>),
MethodCall(Box<MethodCall>),
Tup(ThinVec<P<Expr>>),
Binary(BinOp, P<Expr>, P<Expr>),
Unary(UnOp, P<Expr>),
Lit(Lit),
Cast(P<Expr>, P<Ty>),
Type(P<Expr>, P<Ty>),
Let(P<Pat>, P<Expr>, Span, Recovered),
If(P<Expr>, P<Block>, Option<P<Expr>>),
While(P<Expr>, P<Block>, Option<Label>),
ForLoop {
pat: P<Pat>,
iter: P<Expr>,
body: P<Block>,
label: Option<Label>,
kind: ForLoopKind,
},
Loop(P<Block>, Option<Label>, Span),
Match(P<Expr>, ThinVec<Arm>, MatchKind),
Closure(Box<Closure>),
Block(P<Block>, Option<Label>),
Gen(CaptureBy, P<Block>, GenBlockKind, Span),
Await(P<Expr>, Span),
TryBlock(P<Block>),
Assign(P<Expr>, P<Expr>, Span),
AssignOp(BinOp, P<Expr>, P<Expr>),
Field(P<Expr>, Ident),
Index(P<Expr>, P<Expr>, Span),
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits),
Underscore,
Path(Option<P<QSelf>>, Path),
AddrOf(BorrowKind, Mutability, P<Expr>),
Break(Option<Label>, Option<P<Expr>>),
Continue(Option<Label>),
Ret(Option<P<Expr>>),
InlineAsm(P<InlineAsm>),
OffsetOf(P<Ty>, P<[Ident]>),
MacCall(P<MacCall>),
Struct(P<StructExpr>),
Repeat(P<Expr>, AnonConst),
Paren(P<Expr>),
Try(P<Expr>),
Yield(Option<P<Expr>>),
Yeet(Option<P<Expr>>),
Become(P<Expr>),
IncludedBytes(Lrc<[u8]>),
FormatArgs(P<FormatArgs>),
UnsafeBinderCast(UnsafeBinderCastKind, P<Expr>, Option<P<Ty>>),
Err(ErrorGuaranteed),
Dummy,
}
Variants§
Array(ThinVec<P<Expr>>)
An array (e.g, [a, b, c, d]
).
ConstBlock(AnonConst)
Allow anonymous constants from an inline const
block.
Call(P<Expr>, ThinVec<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.
MethodCall(Box<MethodCall>)
A method call (e.g., x.foo::<Bar, Baz>(a, b, c)
).
Tup(ThinVec<P<Expr>>)
A tuple (e.g., (a, b, c, d)
).
Binary(BinOp, P<Expr>, P<Expr>)
A binary operation (e.g., a + b
, a * b
).
Unary(UnOp, P<Expr>)
A unary operation (e.g., !x
, *x
).
Lit(Lit)
A literal (e.g., 1
, "foo"
).
Cast(P<Expr>, P<Ty>)
A cast (e.g., foo as f64
).
Type(P<Expr>, P<Ty>)
A type ascription (e.g., builtin # type_ascribe(42, usize)
).
Usually not written directly in user code but
indirectly via the macro type_ascribe!(...)
.
Let(P<Pat>, P<Expr>, Span, Recovered)
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.
If(P<Expr>, P<Block>, Option<P<Expr>>)
An if
block, with an optional else
block.
if expr { block } else { expr }
While(P<Expr>, P<Block>, Option<Label>)
A while loop, with an optional label.
'label: while expr { block }
ForLoop
A for
loop, with an optional label.
'label: for await? pat in iter { block }
This is desugared to a combination of loop
and match
expressions.
Loop(P<Block>, Option<Label>, Span)
Conditionless loop (can be exited with break
, continue
, or return
).
'label: loop { block }
Match(P<Expr>, ThinVec<Arm>, MatchKind)
A match
block.
Closure(Box<Closure>)
A closure (e.g., move |a, b, c| a + b + c
).
Block(P<Block>, Option<Label>)
A block ('label: { ... }
).
Gen(CaptureBy, P<Block>, GenBlockKind, Span)
An async
block (async move { ... }
),
or a gen
block (gen move { ... }
).
The span is the “decl”, which is the header before the body { }
including the asyng
/gen
keywords and possibly move
.
Await(P<Expr>, Span)
An await expression (my_future.await
). Span is of await keyword.
TryBlock(P<Block>)
A try block (try { ... }
).
Assign(P<Expr>, P<Expr>, Span)
An assignment (a = foo()
).
The Span
argument is the span of the =
token.
AssignOp(BinOp, P<Expr>, P<Expr>)
An assignment with an operator.
E.g., a += 1
.
Field(P<Expr>, Ident)
Access of a named (e.g., obj.foo
) or unnamed (e.g., obj.0
) struct field.
Index(P<Expr>, P<Expr>, Span)
An indexing operation (e.g., foo[2]
).
The span represents the span of the [2]
, including brackets.
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits)
A range (e.g., 1..2
, 1..
, ..2
, 1..=2
, ..=2
; and ..
in destructuring assignment).
Underscore
An underscore, used in destructuring assignment to ignore a value.
Path(Option<P<QSelf>>, Path)
Variable reference, possibly containing ::
and/or type
parameters (e.g., foo::bar::<baz>
).
Optionally “qualified” (e.g., <Vec<T> as SomeTrait>::SomeType
).
AddrOf(BorrowKind, Mutability, P<Expr>)
A referencing operation (&a
, &mut a
, &raw const a
or &raw mut a
).
Break(Option<Label>, Option<P<Expr>>)
A break
, with an optional label to break, and an optional expression.
Continue(Option<Label>)
A continue
, with an optional label.
Ret(Option<P<Expr>>)
A return
, with an optional value to be returned.
InlineAsm(P<InlineAsm>)
Output of the asm!()
macro.
OffsetOf(P<Ty>, P<[Ident]>)
An offset_of
expression (e.g., builtin # offset_of(Struct, field)
).
Usually not written directly in user code but
indirectly via the macro core::mem::offset_of!(...)
.
MacCall(P<MacCall>)
A macro invocation; pre-expansion.
Struct(P<StructExpr>)
A struct literal expression.
E.g., Foo {x: 1, y: 2}
, or Foo {x: 1, .. rest}
.
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.
Paren(P<Expr>)
No-op: used solely so we can pretty-print faithfully.
Try(P<Expr>)
A try expression (expr?
).
Yield(Option<P<Expr>>)
A yield
, with an optional value to be yielded.
Yeet(Option<P<Expr>>)
A do yeet
(aka throw
/fail
/bail
/raise
/whatever),
with an optional value to be returned.
Become(P<Expr>)
A tail call return, with the value to be returned.
While .0
must be a function call, we check this later, after parsing.
IncludedBytes(Lrc<[u8]>)
Bytes included via include_bytes!
Added for optimization purposes to avoid the need to escape
large binary blobs - should always behave like ExprKind::Lit
with a ByteStr
literal.
FormatArgs(P<FormatArgs>)
A format_args!()
expression.
UnsafeBinderCast(UnsafeBinderCastKind, P<Expr>, Option<P<Ty>>)
Err(ErrorGuaranteed)
Placeholder for an expression that wasn’t syntactically well formed in some way.
Dummy
Acts as a null expression. Lowering it will always emit a bug.
Trait Implementations§
Source§impl<__D: SpanDecoder> Decodable<__D> for ExprKind
impl<__D: SpanDecoder> Decodable<__D> for ExprKind
Auto Trait Implementations§
impl DynSend for ExprKind
impl DynSync for ExprKind
impl Freeze for ExprKind
impl !RefUnwindSafe for ExprKind
impl !Send for ExprKind
impl !Sync for ExprKind
impl Unpin for ExprKind
impl !UnwindSafe for ExprKind
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§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<T> Pointable for T
impl<T> Pointable for 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,
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:
Array
: 15 bytesConstBlock
: 23 bytesCall
: 23 bytesMethodCall
: 15 bytesTup
: 15 bytesBinary
: 31 bytesUnary
: 15 bytesLit
: 15 bytesCast
: 23 bytesType
: 23 bytesLet
: 31 bytesIf
: 31 bytesWhile
: 31 bytesForLoop
: 39 bytesLoop
: 31 bytesMatch
: 23 bytesClosure
: 15 bytesBlock
: 23 bytesGen
: 31 bytesAwait
: 23 bytesTryBlock
: 15 bytesAssign
: 31 bytesAssignOp
: 31 bytesField
: 23 bytesIndex
: 31 bytesRange
: 23 bytesUnderscore
: 0 bytesPath
: 39 bytesAddrOf
: 15 bytesBreak
: 23 bytesContinue
: 15 bytesRet
: 15 bytesInlineAsm
: 15 bytesOffsetOf
: 31 bytesMacCall
: 15 bytesStruct
: 15 bytesRepeat
: 31 bytesParen
: 15 bytesTry
: 15 bytesYield
: 15 bytesYeet
: 15 bytesBecome
: 15 bytesIncludedBytes
: 23 bytesFormatArgs
: 15 bytesUnsafeBinderCast
: 23 bytesErr
: 0 bytesDummy
: 0 bytes