Rust
Constant Evaluation Failed E0080 Fix
E0080 is not a type error or a syntax error: the expression is well-formed, but the compiler must evaluate it at compile time and the evaluation fails - it divides by zero, overflows, indexes out of bounds, or panics. The diagnostic names the failed operation and the constant whose evaluation failed. This guide shows the error in every position that forces compile-time evaluation, the repairs that make the evaluation succeed or move it to runtime, and the neighboring shapes that look the same and are not this error.
Written December 1, 2026 · Tested with Rust 1.99.0 · 13 min read
- The rule underneath: the value is needed before the program runs
- How to read the diagnostic
- The first failure: a const that divides by zero
- The same failure as overflow, an index, and a panic
Written December 1, 2026
Tested with Rust 1.99.0
What this guide is
Error E0080 is a failed compile-time evaluation. The error codes index states it in one line - a constant value failed to get evaluated - and explains that the compiler was unable to sensibly evaluate a constant expression that had to be evaluated, naming division by zero and integer overflow as two ways to induce it. Its erroneous example puts the failing expressions for enum discriminant values: X = (1 << 500) and Y = (1 / 0).
That scope is wider than one const declaration. Any position that forces the compiler to produce a value during compilation can draw E0080: a const item, a static item, an enum discriminant, an array length, a generic const argument, and an associated const. Every one of those positions is shown failing below. The common thread is not the syntax - it is that the value is needed before the program runs, so a failure that would be a runtime panic in ordinary code becomes a compile error here.
The practical payoff is that the repair is about the evaluation, not the declaration. Either make the expression evaluate successfully - a divisor that is not zero, arithmetic that stays in range or wraps on purpose, an index inside the array - or stop asking for the value at compile time and compute it at runtime instead. Both families of repair are shown running below.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: the value is needed before the program runs
A const item has no storage of its own; the compiler evaluates its expression during compilation — a failing const item draws E0080 even when nothing in the program uses it — and it must evaluate cleanly or there is no value to use. A static, an enum discriminant, an array length, and a const generic argument are stricter still: the compiler needs the actual number to lay out memory, assign discriminant values, or pick a type. In all of these positions the evaluation is not optional and cannot be deferred, which is why the failure is reported as an error in the constant rather than as a warning about the code that uses it.
The evaluation also follows the checked rules, whatever the build profile would do at runtime. Arithmetic in a constant expression is checked arithmetic: 200u8 + 100 fails evaluation even though the same expression in release-mode runtime code would wrap. Integer division by zero, an out-of-bounds constant index, and a panic! reached during evaluation fail the same way. Floating-point division by zero is defined instead: 1.0 / 0.0 in a const evaluates to infinity and draws no error. What does not fail is an operation defined to always produce a value: a cast that truncates, such as -1i32 as u8, evaluates to 255 and draws no error at all - that boundary is shown in full below.
How to read the diagnostic
An E0080 failure is headed by the failed operation itself: "attempt to divide 1_i32 by zero", "attempt to compute 200_u8 + 100_u8, which would overflow", "index out of bounds: the length is 3 but the index is 5", "attempt to calculate the remainder of 5_i32 with a divisor of zero", "attempt to negate i8::MIN, which would overflow", or "evaluation panicked" followed by the panic message. The span underlines the failing expression and labels it with the constant whose evaluation failed - "evaluation of X failed here" for a named item, "evaluation of main::{constant#0} failed here" for an anonymous constant such as an array length.
Two follow-on shapes are worth recognizing. When other code uses the failed constant, the diagnostic adds "note: erroneous constant encountered" pointing at each use site - the same note can appear more than once for one use. And when the failing expression sits inside a const fn called from a constant, the span label reads "evaluation of X failed inside this call", with a second note, "inside boom", pointing at the exact expression inside the function where the failure occurred. Read the header first: it says which operation failed, and that operation - not the item's type or name - is what the repair has to change.
The first failure: a const that divides by zero
The smallest shape is a const item whose expression divides by zero, printed in main:
const X: i32 = 1 / 0;
fn main() { println!("{}", X); }
error[E0080]: attempt to divide `1_i32` by zero
--> fail_const_div_zero.rs:1:16
|
1 | const X: i32 = 1 / 0;
| ^^^^^ evaluation of `X` failed here
note: erroneous constant encountered
--> fail_const_div_zero.rs:2:28
|
2 | fn main() { println!("{}", X); }
| ^
note: erroneous constant encountered
--> fail_const_div_zero.rs:2:28
|
2 | fn main() { println!("{}", X); }
| ^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
Nothing is wrong with the type, the item, or the println!. The one defect is that 1 / 0 has no value, and a const must have a value. The header names the operation and the operands, the span names the constant whose evaluation failed, and the two identical notes mark the use site in main where the missing value was needed.
The same failure as overflow, an index, and a panic
Overflow in a constant is the second cause the index names. The expression is ordinary checked arithmetic and the result does not fit the type:
const X: u8 = 200 + 100;
fn main() { println!("{}", X); }
error[E0080]: attempt to compute `200_u8 + 100_u8`, which would overflow
--> fail_const_overflow.rs:1:15
|
1 | const X: u8 = 200 + 100;
| ^^^^^^^^^ evaluation of `X` failed here
note: erroneous constant encountered
--> fail_const_overflow.rs:2:28
|
2 | fn main() { println!("{}", X); }
| ^
note: erroneous constant encountered
--> fail_const_overflow.rs:2:28
|
2 | fn main() { println!("{}", X); }
| ^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
An index into a constant array is evaluated too, so an out-of-bounds index fails at compile time instead of panicking at runtime:
const A: [i32; 3] = [1, 2, 3];
const X: i32 = A[5];
fn main() { println!("{}", X); }
error[E0080]: index out of bounds: the length is 3 but the index is 5
--> fail_const_index_oob.rs:2:16
|
2 | const X: i32 = A[5];
| ^^^^ evaluation of `X` failed here
note: erroneous constant encountered
--> fail_const_index_oob.rs:3:28
|
3 | fn main() { println!("{}", X); }
| ^
note: erroneous constant encountered
--> fail_const_index_oob.rs:3:28
|
3 | fn main() { println!("{}", X); }
| ^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
And a panic! reached during evaluation fails with the panic's own message carried into the header:
const X: i32 = panic!("boom in const");
fn main() { println!("{}", X); }
error[E0080]: evaluation panicked: boom in const
--> fail_const_panic_msg.rs:1:16
|
1 | const X: i32 = panic!("boom in const");
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `X` failed here
note: erroneous constant encountered
--> fail_const_panic_msg.rs:2:28
|
2 | fn main() { println!("{}", X); }
| ^
note: erroneous constant encountered
--> fail_const_panic_msg.rs:2:28
|
2 | fn main() { println!("{}", X); }
| ^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
A compile-time assertion is the deliberate form of that last shape - a const _: () = assert!(...) item exists precisely to fail evaluation when its condition is false:
const _: () = assert!(1 + 1 == 3, "math broke");
fn main() { println!("hi"); }
error[E0080]: evaluation panicked: math broke
--> fail_const_assert.rs:1:15
|
1 | const _: () = assert!(1 + 1 == 3, "math broke");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
Note the difference in shape: the assertion's diagnostic has no "erroneous constant encountered" note, because nothing uses the anonymous _ item - the failure is the whole point of the item, and there is no use site to point at.
The position does not save you: static, discriminant, array length, generic argument
A static item is evaluated at compile time just as a const is, and draws the identical error and header:
static X: i32 = 1 / 0;
fn main() { println!("{}", X); }
error[E0080]: attempt to divide `1_i32` by zero
--> fail_static_div_zero.rs:1:17
|
1 | static X: i32 = 1 / 0;
| ^^^^^ evaluation of `X` failed here
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
An enum discriminant is the index's own example position. A shift that overflows the discriminant type fails evaluation:
enum E { X = (1 << 500) }
fn main() { println!("hi"); }
error[E0080]: attempt to shift left by `500_i32`, which would overflow
--> fail_enum_disc_shift.rs:1:14
|
1 | enum E { X = (1 << 500) }
| ^^^^^^^^^^ evaluation of `E::X::{constant#0}` failed here
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
An array length is an anonymous constant the compiler must know to type the array, so a failing length expression draws E0080 even though it sits inside a function body:
fn main() { let _a: [u8; 1 / 0] = [0]; println!("hi"); }
error[E0080]: attempt to divide `1_usize` by zero
--> fail_array_len_div_zero.rs:1:26
|
1 | fn main() { let _a: [u8; 1 / 0] = [0]; println!("hi"); }
| ^^^^^ evaluation of `main::{constant#0}` failed here
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
A const generic argument is the same kind of position - the value becomes part of a type - and fails the same way:
struct Buf<const N: usize>;
fn main() { let _b: Buf<{ 1 / 0 }> = Buf; println!("hi"); }
error[E0080]: attempt to divide `1_usize` by zero
--> fail_generic_const_arg.rs:2:27
|
2 | fn main() { let _b: Buf<{ 1 / 0 }> = Buf; println!("hi"); }
| ^^^^^ evaluation of `main::{constant#0}` failed here
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
In each case the span label tells you which constant failed: a named item by name, a discriminant as E::X::{constant#0}, an inline length or generic argument as main::{constant#0}. The repair never depends on the position; it depends on the operation in the header.
Distance: a failure that travels through other constants
A failed constant does not stay contained. When a second constant is defined from the failing one, the diagnostic still reports the original operation, and the "erroneous constant encountered" notes mark every step the failure traveled through - here, the definition of C from B, and the use of C in main:
const A: u8 = 250;
const B: u8 = A * 3;
const C: u8 = B + 10;
fn main() { println!("{}", C); }
error[E0080]: attempt to compute `250_u8 * 3_u8`, which would overflow
--> fail_const_mul_overflow_multi.rs:2:15
|
2 | const B: u8 = A * 3;
| ^^^^^ evaluation of `B` failed here
note: erroneous constant encountered
--> fail_const_mul_overflow_multi.rs:3:15
|
3 | const C: u8 = B + 10;
| ^
note: erroneous constant encountered
--> fail_const_mul_overflow_multi.rs:4:28
|
4 | fn main() { println!("{}", C); }
| ^
note: erroneous constant encountered
--> fail_const_mul_overflow_multi.rs:4:28
|
4 | fn main() { println!("{}", C); }
| ^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
The header is about B's multiplication, because that is where evaluation actually failed; C itself contains no failing operation. When you see this shape, fix the constant named in the span label - "evaluation of B failed here" - not the one whose use site the notes point at.
An associated const in a trait behaves the same way, with one addition: because the overflowing expression also trips the arithmetic_overflow lint, that program reports two errors - the lint error first, then E0080 naming the evaluation of <S as T>::N - and aborts "due to 2 previous errors". The E0080 half is the same error; the lint is a second, independent report of the same expression.
The boundary: the same const fn called only at runtime
A const fn is only evaluated at compile time when it is called in a constant context. The identical function, called only from main, compiles with no error at all - and then panics when the program runs:
const fn boom() -> i32 { panic!("runtime boom") }
fn main() { println!("{}", boom()); }
$ ./runtime_const_fn_panics.bin
thread 'main' panicked at runtime_const_fn_panics.rs:1:26:
runtime boom
(exit 101)
There is no E0080 anywhere in that outcome: no constant was ever evaluated, so there was nothing for the compiler to fail on. Put the same call in a const item and the same panic becomes E0080:
const fn boom() -> i32 { panic!("const fn boom") }
const X: i32 = boom();
fn main() { println!("{}", X); }
error[E0080]: evaluation panicked: const fn boom
--> fail_const_fn_in_const.rs:2:16
|
2 | const X: i32 = boom();
| ^^^^^^ evaluation of `X` failed inside this call
|
note: inside `boom`
--> fail_const_fn_in_const.rs:1:26
|
1 | const fn boom() -> i32 { panic!("const fn boom") }
| ^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
note: erroneous constant encountered
--> fail_const_fn_in_const.rs:3:28
|
3 | fn main() { println!("{}", X); }
| ^
note: erroneous constant encountered
--> fail_const_fn_in_const.rs:3:28
|
3 | fn main() { println!("{}", X); }
| ^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
The span label is the tell - "evaluation of X failed inside this call" - and the "inside boom" note points into the function body at the panic!. So the question to ask about a panicking const fn is never whether the function is correct in the abstract; it is whether any caller forces it to run during compilation.
A second boundary is quieter. Not every suspicious constant expression fails evaluation: a cast is defined for every input, so -1i32 as u8 in a const evaluates cleanly to 255, compiles, and prints 255. If a constant expression surprises you by compiling, check whether its operations are the always-defined kind - casts, wrapping_* arithmetic - before assuming the compiler missed a failure.
The repair: make the evaluation succeed
The direct repair keeps the value at compile time and fixes the operation. A nonzero divisor:
const X: i32 = 10 / 2;
fn main() { println!("{}", X); }
5
The output is 5. An in-bounds index:
const A: [i32; 3] = [1, 2, 3];
const X: i32 = A[2];
fn main() { println!("{}", X); }
3
The output is 3. Where wrapping is the intended semantics, say so in the expression - wrapping_add is defined on overflow, so the evaluation succeeds and yields the wrapped result:
const X: u8 = 200u8.wrapping_add(100);
fn main() { println!("{}", X); }
44
The output is 44 - 200 + 100 modulo 256. And where the honest answer is "this does not fit", checked arithmetic turns the failed evaluation into a value the program can handle: checked_add returns an Option, and an Option is a perfectly good constant:
const X: Option<u8> = 200u8.checked_add(100);
fn main() { println!("{:?}", X); }
None
The output is None - the overflow is now data, decided at compile time, instead of a failed evaluation.
The repair: move the computation to runtime
When the inputs are not known until the program runs, the value was never a constant to begin with. Computing at runtime means a bad input is a runtime event the program can respond to, instead of a compile error:
fn compute(d: i32) -> i32 { 1 / d }
fn main() {
let d = std::env::args().count() as i32 - 1;
let r = std::panic::catch_unwind(|| compute(d - d));
println!("caught: {}", r.is_err());
}
caught: true
The output is caught: true - the division by zero panicked at runtime and catch_unwind caught it; the program decided what the failure meant instead of failing to compile. The trade is real in both directions: a runtime computation gives up the compile-time guarantee and the use of the value in types, array lengths, and other constant positions. Move a computation to runtime only when no constant position needs its value.
A const fn that is sound for the inputs it will actually receive needs no repair at all in either world - the same function evaluates in a constant and runs at runtime:
const fn safe(x: i32) -> i32 { x + 1 }
const X: i32 = safe(41);
fn main() { println!("{} {}", X, safe(1)); }
42 2
The output is 42 2: the constant X evaluated at compile time, and the runtime call computed its own result.
Fixes in reach order
First, read the header. It names the exact operation that failed - a division by zero, an overflowing computation, an out-of-bounds index, a shift that overflows, or a panic with its message. That operation is the defect; the item's name in the span label is only where it surfaced.
Second, if the span label names a different constant than the one you were editing - "evaluation of B failed here" while the notes point at C and at main - fix the named constant. The notes mark where the missing value was needed, not where it failed.
Third, fix the operation in place when the value must stay constant: a divisor that cannot be zero, a wider type or checked_* arithmetic when the result can exceed the type, wrapping_* or saturating_* when that behavior is the intent, an index inside the array's length.
Last, if the inputs are runtime values, drop the const and compute at runtime. Expect the failure mode to change with it: the same bad input becomes a runtime panic, catchable and testable, and the value can no longer appear in constant positions.
Decision summary
E0080 fired exactly when an expression the compiler had to evaluate at compile time failed during that evaluation: integer division by zero in a const, a static, an enum discriminant, an array length, and a generic const argument; overflow in a const, in a multi-step chain of constants, and in a trait's associated const (which additionally drew the arithmetic_overflow lint error); an out-of-bounds index into a constant array; a panic! in a const expression; a failing compile-time assert!; a shift overflowing a discriminant; and a const fn that panicked when called from a const item. The same const fn called only at runtime drew no E0080 - it compiled and panicked at runtime with exit 101 - and a truncating cast in a const drew no error at all, evaluating to 255. Compiling and running were: a nonzero divisor, an in-bounds index, wrapping_add yielding the wrapped value, checked_add yielding None as a constant, a runtime computation whose panic was caught, and a sound const fn evaluated both at compile time and at runtime.
Checklist
- Read the header: it names the failed operation - division by zero, overflow, out-of-bounds index, overflowing shift, or a panic message.
- Fix the constant in the span label ("evaluation of
Nfailed here"), not the use sites in the "erroneous constant encountered" notes. - Overflow in a constant is checked arithmetic in every profile - widen the type, or use
checked_*,wrapping_*, orsaturating_*to state the intended behavior. - A panicking
const fnis E0080 only when a constant context calls it; a runtime-only call panics at runtime instead. - A cast that truncates is not a failed evaluation - it always produces a value.
- If the inputs are runtime values, the item should not be a
constat all; compute at runtime and handle the panic there. - A failing
const _: () = assert!(...)is the deliberate form of this error - read its message as the assertion's own report.
Related guides on this site
- E0158 Constant Pattern Generic Parameter Fix
- Mutable Reference in Constant E0764 Fix
- E0435 Non-Constant Value in Constant Fix
- E0433 Failed to Resolve Fix
Sources
- Rust error codes index, E0080 - a constant value failed to get evaluated; the compiler was unable to sensibly evaluate a constant expression that had to be evaluated; division by zero and integer overflow are two ways to induce this error; the erroneous example places the failing expressions for enum discriminant values, and the entry points to the Reference's Discriminants section for setting custom integer types on enums with the
reprattribute. - The Rust Reference, Constant evaluation - what constant evaluation is, which expressions are evaluated at compile time, and the operations that are forbidden or fail in constant contexts.
- The Rust Reference, Discriminants - how enum discriminant expressions are evaluated and the integer types they are evaluated as.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.