Caution

You’re reading a draft of the Ferrocene Language Specification. Some parts of this document might be missing, incomplete or incorrect. Our aim is to have the specification ready by the end of 2022.

8. Statements

Syntax

Statement ::=
    ExpressionStatement
  | Item
  | LetStatement
  | TerminatedMacroInvocation
  | ;

Legality Rules

8:1 An expression statement is an expression whose result is ignored.

8:2 An item statement is a statement that is expressed as an item.

8:3 An empty statement is a statement expressed as character 0x3B (semicolon).

8:4 A macro statement is a statement expressed as a terminated macro invocation.

Dynamic Semantics

8:5 Execution is the process by which a statement achieves its runtime effects.

8:6 The execution of an empty statement has no effect.

8.1. Let Statements

Syntax

LetStatement ::=
    OuterAttributeOrDoc* let PatternWithoutAlternation TypeAscription? (= Expression)? ;

Legality Rules

8.1:1 A let statement is a statement that introduces new bindings produced by its pattern-without-alternation.

8.1:2 The type of a variable introduced by a let statement is determined as follows:

8.1:5 The value of a variable introduced by a let statement is determined as follows:

8.1:8 The pattern of a let statement shall be irrefutable.

Dynamic Semantics

8.1:9 The execution of a let statement proceeds as follows:

  1. 8.1:10 If the let statement appears with an expression, then:

    1. 8.1:11 The expression is evaluated.

    2. 8.1:12 The value of the expression is assigned to each variable introduced by the let statement.

Examples

let local = 0;
let local: u32;
let (a, b) = (0, 0);

8.2. Expression Statements

Syntax

ExpressionStatement ::=
    ExpressionWithBlock ;?
  | ExpressionWithoutBlock ;

Legality Rules

8.2:1 An expression statement is an expression whose result is ignored.

8.2:2 The expected type of an expression statement without character 0x3B (semicolon) is the unit type.

Dynamic Semantics

8.2:3 The execution of an expression statement proceeds as follows:

  1. 8.2:4 The operand is evaluated.

  2. 8.2:5 The value of the operand is dropped.

Examples

let mut values = vec![1, 2, 3];

8.2:6 The following expression statement ignores the result from pop().

values.pop();

8.2:7 The following expression statement does not require a semicolon.

if values.is_empty() {
    values.push(42);
}
else {
    values.remove(0);
}

8.2:8 The following expression statement is not an index expression.

[42];