For now, this reference is a best-effort document. We strive for validity and completeness, but are not yet there. In the future, the docs and lang teams will work together to figure out how best to do this. Until then, this is a best-effort attempt. If you find something wrong or missing, file an issue or send in a pull request.

Constant evaluation

Constant evaluation is the process of computing the result of expressions during compilation. Only a subset of all expressions can be evaluated at compile-time.

Constant expressions

Certain types of expressions can be evaluated at compile time. These are called constant expressions and are required in const contexts. In other places, such as in let statements, constant expressions may be evaluated at compile time. If errors, such as out of bounds array indexing or overflow occurs, then it is a compiler error if the value must be evaluated at compile time, otherwise it is just a warning, but the code will most likely panic when run.

The following expressions are constant expressions, so long as any operands are also constant expressions and do not cause any Drop::drop calls to be ran.

Const context

A const context is one of the following: