Tuple Types

A tuple type is a fixed-arity, heterogeneous product of element types. It is written as a parenthesised, comma-separated list of types. A tuple type with N elements has the form (T0, T1, ..., TN-1).

A 1-tuple type MUST be written with a trailing comma: (T,). The form (T) (without a trailing comma) is a parenthesised type and is not a tuple.

The zero-arity tuple type () is the unit type (see Unit Type). The unit type and the empty tuple are the same type.

Two tuple types are the same type if and only if they have the same arity and their element types are the same in order.

A tuple type is @copy if and only if every element type is @copy. Otherwise the tuple is moved on use, subject to the same affine-type rules as other non-copy aggregates.

An element of a tuple value t is accessed with the expression t.N, where N is a non-negative integer literal in decimal form (see Tuple Expressions). Indexing out of bounds (N >= arity) is a compile-time error.

If a tuple element type is not @copy, the element MUST NOT be consumed via field access (t.N). To consume individual elements, the tuple MUST be destructured (see Let Statements).

let p: (i32, bool) = (42, true);  // 2-tuple
let one: (i32,) = (42,);           // 1-tuple (trailing comma required)
let u: () = ();                    // unit type
let nested: ((i32, i32), bool) = ((1, 2), false);