#[non_exhaustive]
pub enum Stmt {
Show 17 variants
Noop(Position),
If(Box<(Expr, StmtBlock, StmtBlock)>, Position),
Switch(Box<(Expr, SwitchCasesCollection)>, Position),
While(Box<(Expr, StmtBlock)>, Position),
Do(Box<(Expr, StmtBlock)>, ASTFlags, Position),
For(Box<(Ident, Ident, Expr, StmtBlock)>, Position),
Var(Box<(Ident, Expr, Option<NonZeroUsize>)>, ASTFlags, Position),
Assignment(Box<(OpAssignment, BinaryExpr)>),
FnCall(Box<FnCallExpr>, Position),
Block(Box<StmtBlock>),
TryCatch(Box<TryCatchBlock>, Position),
Expr(Box<Expr>),
BreakLoop(ASTFlags, Position),
Return(Option<Box<Expr>>, ASTFlags, Position),
Import(Box<(Expr, Ident)>, Position),
Export(Box<(Ident, Ident)>, Position),
Share(ImmutableString, Position),
}
Expand description
(internals) A statement.
Exported under the internals
feature only.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Noop(Position)
No-op.
If(Box<(Expr, StmtBlock, StmtBlock)>, Position)
if
expr {
stmt }
else
{
stmt }
Switch(Box<(Expr, SwitchCasesCollection)>, Position)
switch
expr {
literal or range or _ if
condition =>
stmt ,
… }
Data Structure
- Hash table for (condition, block)
- Default block
- List of ranges: (start, end, inclusive, condition, statement)
While(Box<(Expr, StmtBlock)>, Position)
while
expr {
stmt }
| loop
{
stmt }
If the guard expression is UNIT
, then it is a loop
statement.
Do(Box<(Expr, StmtBlock)>, ASTFlags, Position)
For(Box<(Ident, Ident, Expr, StmtBlock)>, Position)
for
(
id ,
counter )
in
expr {
stmt }
Var(Box<(Ident, Expr, Option<NonZeroUsize>)>, ASTFlags, Position)
Assignment(Box<(OpAssignment, BinaryExpr)>)
expr op=
expr
FnCall(Box<FnCallExpr>, Position)
func (
expr ,
… )
Note - this is a duplicate of Expr::FnCall
to cover the very common pattern of a single
function call forming one statement.
Block(Box<StmtBlock>)
{
stmt;
… }
TryCatch(Box<TryCatchBlock>, Position)
try
{
stmt; … }
catch
(
var )
{
stmt; … }
Expr(Box<Expr>)
BreakLoop(ASTFlags, Position)
Return(Option<Box<Expr>>, ASTFlags, Position)
Import(Box<(Expr, Ident)>, Position)
import
expr as
alias
Not available under no_module
.
Export(Box<(Ident, Ident)>, Position)
export
var as
alias
Not available under no_module
.
Share(ImmutableString, Position)
Convert a variable to shared.
Not available under no_closure
.
Notes
This variant does not map to any language structure. It is currently only used only to convert a normal variable into a shared variable when the variable is captured by a closure.
Implementations
sourceimpl Stmt
impl Stmt
sourcepub fn set_position(&mut self, new_pos: Position) -> &mut Self
pub fn set_position(&mut self, new_pos: Position) -> &mut Self
Override the position of this statement.
sourcepub const fn returns_value(&self) -> bool
pub const fn returns_value(&self) -> bool
Does this statement return a value?
sourcepub const fn is_self_terminated(&self) -> bool
pub const fn is_self_terminated(&self) -> bool
Is this statement self-terminated (i.e. no need for a semicolon terminator)?
sourcepub fn is_block_dependent(&self) -> bool
pub fn is_block_dependent(&self) -> bool
Does this statement’s behavior depend on its containing block?
A statement that depends on its containing block behaves differently when promoted to an upper block.
Currently only variable definitions (i.e. let
and const
), import
/export
statements,
and eval
calls (which may in turn define variables) fall under this category.
sourcepub fn is_internally_pure(&self) -> bool
pub fn is_internally_pure(&self) -> bool
Is this statement pure within the containing block?
An internally pure statement only has side effects that disappear outside the block.
Currently only variable definitions (i.e. let
and const
) and import
/export
statements are internally pure, other than pure expressions.
sourcepub const fn is_control_flow_break(&self) -> bool
pub const fn is_control_flow_break(&self) -> bool
Does this statement break the current control flow through the containing block?
Currently this is only true for return
, throw
, break
and continue
.
All statements following this statement will essentially be dead code.
Trait Implementations
sourceimpl Extend<Stmt> for StmtBlock
impl Extend<Stmt> for StmtBlock
sourcefn extend<T: IntoIterator<Item = Stmt>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Stmt>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Stmt
impl !Send for Stmt
impl !Sync for Stmt
impl Unpin for Stmt
impl !UnwindSafe for Stmt
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more