Skip to main content

Stmt

Enum Stmt 

Source
pub enum Stmt {
Show 21 variants Nop, Expr(Expr), Let { object: ObjectId, init: Expr, explicit: bool, }, Vla(Box<VlaDef>), Cleanup(Box<CleanupDef>), Block(Vec<Stmt>), If { cond: Expr, then_branch: Box<Stmt>, else_branch: Option<Box<Stmt>>, }, While { id: LoopId, cond: Expr, body: Box<Stmt>, range: SourceRange, }, DoWhile { id: LoopId, body: Box<Stmt>, cond: Expr, range: SourceRange, }, For { id: LoopId, init: Vec<Stmt>, cond: Option<Expr>, step: Option<Expr>, body: Box<Stmt>, range: SourceRange, }, Switch(Box<Switch>), SwitchTree(Box<SwitchTree>), Case { switch: SwitchId, value: Option<CaseRange>, body: Box<Stmt>, range: SourceRange, }, Label { id: LabelId, body: Box<Stmt>, range: SourceRange, }, Region(Box<Region>), Goto { id: LabelId, range: SourceRange, }, GotoPtr { target: Expr, range: SourceRange, }, Break { target: BreakTarget, range: SourceRange, }, Continue { id: LoopId, range: SourceRange, }, Return { value: Option<Expr>, range: SourceRange, }, Asm(Box<AsmStmt>),
}
Expand description

A typed statement.

Variants§

§

Nop

The null statement.

§

Expr(Expr)

An expression evaluated for its side effects.

§

Let

A local variable definition. C leaves an uninitialised local indeterminate; the initialiser here is a zero of the right type in that case, so that the generated Rust never reads uninitialised memory.

Fields

§object: ObjectId

The object being defined.

§init: Expr

Its initial value, already converted to the object’s type.

§explicit: bool

Whether the source wrote an initialiser at all.

It decides what happens when the definition has to be hoisted out of the block it was written in — out of a switch body, or to the top of a function lowered into a control-flow graph. The hoisted definition zero-initialises; only an initialiser the program actually wrote has to run again where it was written.

§

Vla(Box<VlaDef>)

The definition of a variable length array (C99 6.7.5.2).

It is a Stmt::Let with two bindings instead of one, because the object needs storage whose size is only known here; see VlaDef.

§

Cleanup(Box<CleanupDef>)

T x __attribute__((cleanup(f))); — the registration of the call that runs when x goes out of scope. See CleanupDef.

§

Block(Vec<Stmt>)

A compound statement.

§

If

if (cond) then_branch else else_branch

Fields

§cond: Expr

The controlling expression.

§then_branch: Box<Stmt>

Taken when cond is non-zero.

§else_branch: Option<Box<Stmt>>

Taken otherwise.

§

While

while (cond) body

Fields

§id: LoopId

This loop’s identity.

§cond: Expr

The controlling expression.

§body: Box<Stmt>

The loop body.

§range: SourceRange

Where the statement was written.

§

DoWhile

do body while (cond);

Fields

§id: LoopId

This loop’s identity.

§body: Box<Stmt>

The loop body.

§cond: Expr

The controlling expression.

§range: SourceRange

Where the statement was written.

§

For

for (init; cond; step) body

Fields

§id: LoopId

This loop’s identity.

§init: Vec<Stmt>

The init clause, which may declare variables scoped to the loop.

§cond: Option<Expr>

The controlling expression; absent means “always true”.

§step: Option<Expr>

The iteration expression.

§body: Box<Stmt>

The loop body.

§range: SourceRange

Where the statement was written.

§

Switch(Box<Switch>)

switch (scrutinee) { … }

§

SwitchTree(Box<SwitchTree>)

switch (scrutinee) body, with the body left as a statement tree.

Only produced in CFG mode, where the labels stay where they were written — a case inside a nested statement (Duff’s device) is simply another edge into the loop the CFG builds.

§

Case

case value: or default: inside a Stmt::SwitchTree.

Fields

§switch: SwitchId

The switch the label belongs to.

§value: Option<CaseRange>

The values that enter here, or None for default:.

§body: Box<Stmt>

The labelled statement.

§range: SourceRange

Where the label was written.

§

Label

label: body — a goto target.

Fields

§id: LabelId

The label’s identity.

§body: Box<Stmt>

The labelled statement.

§range: SourceRange

Where the label was written.

§

Region(Box<Region>)

A labelled region a goto leaves, in the structured lowering.

Only produced by regions, which is where the shape and the two kinds are described. A Stmt::Goto inside one names its label and becomes break or continue accordingly.

§

Goto

goto label;

Fields

§id: LabelId

The label jumped to.

§range: SourceRange

Where the statement was written.

§

GotoPtr

GNU’s computed goto *e;, whose operand is a label address.

Only produced in CFG mode, which is the only mode a function containing one is lowered in.

Fields

§target: Expr

The pointer jumped through.

§range: SourceRange

Where the statement was written.

§

Break

break;

Fields

§target: BreakTarget

What the break leaves.

§range: SourceRange

Where the statement was written.

§

Continue

continue;

Fields

§id: LoopId

The loop the continue restarts.

§range: SourceRange

Where the statement was written.

§

Return

return; or return expr;

Fields

§value: Option<Expr>

The returned value.

§range: SourceRange

Where the statement was written.

§

Asm(Box<AsmStmt>)

GNU inline assembly, mapped onto core::arch::asm!; see AsmStmt.

It has no control flow of its own (asm goto is refused), so the control-flow graph carries it as a simple statement.

Implementations§

Source§

impl Stmt

Source

pub fn is_cleanup(&self) -> bool

Whether this is a cleanup registration.

Trait Implementations§

Source§

impl Clone for Stmt

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stmt

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Stmt

§

impl RefUnwindSafe for Stmt

§

impl Send for Stmt

§

impl Sync for Stmt

§

impl Unpin for Stmt

§

impl UnsafeUnpin for Stmt

§

impl UnwindSafe for Stmt

Blanket Implementations§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.