Block Expressions
A block expression is a sequence of statements followed by an optional expression, enclosed in braces.
block_expr = "{" { statement } [ expression ] "}" ;
A block expression with a final expression evaluates to that expression's value, and its type is that expression's type. (A block elaborates to a let/sequence chain, and a sequence evaluates to its tail — core calculus docs/formal/01-core-calculus.md §4.3, §6.7.)
A block expression with no final expression — one that ends with a statement, or is empty — evaluates to () and has type ().
Variables declared in a block are local to that block and shadow any outer variables with the same name.
fn main() -> i32 {
let x = 1;
let y = {
let x = 10; // shadows outer x
x + 5
};
x + y // 1 + 15 = 16
}
When a block exits, the live bindings declared in it are dropped, newest-first (3.9:4, 3.9:18; core calculus docs/formal/01-core-calculus.md §6.7, rule (D-EndScope)).