7:1 A value is either a literal or the result of a computation, that may be stored in a memory location, and interpreted based on some type.
7:3 Both values are the same, or
7:4 One value is of an abstract data type and the other denotes a field of the same value, or
7:5 One value denotes an array and the other denotes an element of the same value, or
7:7 An value is valid when it has been initialized by all reachable control flow paths.
7:8 It is undefined behavior to create a value from uninitialized memory.
ConstantDeclaration::= const (
7.1:1 A constant is an immutable value whose uses are substituted by the value.
7.1:2 An unnamed constant is a constant declared with character 0x5F (low line).
The type specification of a constant shall have
The type of a constant shall implement the
7.1:5 A constant initializer is a construct that provides the value of its related constant.
7.1:6 A constant shall have a constant initializer, unless it is an associated trait constant.
7.1:7 The expression of a constant initializer shall be a constant expression.
7.1:8 The value of a constant is determined by evaluating its constant initializer.
7.1:9 A use of a constant is a value expression and creates a copy of the constant’s value.
7.1:10 The elaboration of a constant evaluates its constant initializer.
7.1:11 A path that refers to a constant is replaced with the value of the constant.
const ZERO: u32 = 0;
StaticDeclaration::= static mut?
7.2:1 A static is a value that is associated with a specific memory location.
7.2:2 A static defined within a generic function exists once in the output executable or library.
The type specification of a static shall have
The type of a static shall implement the
7.2:5 A mutable static is a static whose value can be modified.
7.2:6 Access to a mutable static shall require unsafe context.
7.2:7 An immutable static is a static whose value cannot be modified.
The type of an immutable static shall implement the
7.2:9 A static initializer is a construct that provides the value of its related static.
7.2:10 A static shall have a static initializer, unless it is an external static.
7.2:11 The expression of a static initializer shall be a constant expression.
7.2:12 A use of a static is a place expression referring to the unique location of the static.
7.2:13 The elaboration of a static evaluates its static initializer.
7.2:14 All paths that refer to a static refer to the same memory location.
7.2:15 A static is not dropped during destruction.
7.2:16 A mutable static whose type is not subject to interior mutability may reside in read-only memory.
7.2:17 It is undefined behavior to mutate an immutable static whose type is not subject to interior mutability.
static mut GLOBAL: u32 = 0;
7.3:1 A temporary is an anonymous variable produced by some intermediate computation.
7.4:1 A variable is a placeholder for a value that is allocated on the stack.
7.4:2 The following constructs are variables:
7.4:5 A variable shall be used only after it has been initialized through all reachable control flow paths.
7.4:6 A variable is not initialized when allocated.
7.4.1. Constant Promotion¶
7.4.1:1 Constant promotion is the process of converting a value expression into a constant.
7.4.1:2 Constant promotion is possible only when
7.4.1:3 The value expression is a constant expression, and
7.4.1:4 The type of the value expression does not have a destructor, and
7.4.1:5 The value expression does not employ a struct expression constructing a
7.4.1:6 The value expression only consists of operations that will always succeed evaluation, and
7.4.1:7 The value expression is the operand of an immutable borrow expression.
Constant promotion is always possible for expression
promoting the produced mutable borrow to have
7.4.1:9 Constant promotion proceeds as follows:
7.4.1:10 An anonymous constant is created, whose constant initializer holds the result of the value expression.
7.4.1:11 The value of the anonymous constant is borrowed with