Constant value not known at compile time
ErrorA constant's value is made of literals, operators, the conversions that cannot fail, i64(x) of a u8 or a char and f64(n), and constants declared above it. Arithmetic and comparisons on f64 fold too, to what the program would compute at run time, nan and the infinities included. A conversion that can fail, u8(x), char(x) or i64(x) of an f64, is E0100. A call, a variable, an array, an if or a block is not known until the program runs. Interpolation does not fold either, even of constants: join string constants with +. A number cannot become a string in a constant.
Why
The compiler computes each constant's value before the program runs. Every part of the value must be known then, on both sides of && and || too: a part that run time would skip must still be one the compiler can read. Compute the value from literals and earlier constants, or use a let in a function.
Broken
fn limit() -> i64 {
100
}
const LIMIT = limit()
fn main() {
print(LIMIT)
}
What sisu says
error[E0086]: a constant's value must be known at compile time --> E0086.sisu:5:15 | 5 | const LIMIT = limit() | ^^^^^^^ | = help: use literals, operators and earlier constants sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0086
Fixed
const LIMIT = 100
fn main() {
print(LIMIT)
}
Sisu