Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0434: Const expr not supported

CodeCategoryStability
E0434Struct and enumPermanent

Explanation

Rue encountered an expression that is not supported as a constant value. Constant initializers accept the language's comptime-evaluable forms, string literals, module expressions, and function references used as callable aliases; ordinary runtime computation is rejected. A callable alias is not a first-class runtime value and is supported only as the callee of a call.

Likely cause

A constant initializer calls a runtime function, constructs an aggregate value, or otherwise depends on evaluation available only while the program runs; alternatively, code uses a callable alias as an ordinary value. Replace an initializer with supported constant operations and constant references, move the computation into a function, or invoke a callable alias directly.

Examples

Call a runtime function in a constant initializer

fn answer() -> i32 { 42 }
const ANSWER: i32 = answer();
fn main() -> i32 { 0 }

Use comptime-evaluable constant arithmetic

const BASE: i32 = 40;
const ANSWER: i32 = BASE + 2;
fn main() -> i32 { ANSWER }

References