Rust errors / Const, static and compile-time
Rust compiler error · checked with rustc 1.99.0
Rust error E0080: attempt to shift left by `500_i32`, which would overflow
What it meansA constant value failed to get evaluated.
What rustc prints
error[E0080]: attempt to shift left by `500_i32`, which would overflow
--> main.rs:2:9
|
2 | X = (1 << 500),
| ^^^^^^^^^^ evaluation of `Enum::X::{constant#0}` failed hereReal output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
A constant value failed to get evaluated.
Erroneous code example:
enum Enum {
X = (1 << 500),
Y = (1 / 0),
}
This error indicates that the compiler was unable to sensibly evaluate a constant expression that had to be evaluated. Attempting to divide by 0 or causing an integer overflow are two ways to induce this error.
Ensure that the expressions given can be evaluated as the desired integer type.
See the [Discriminants] section of the Reference for more information about setting custom integer types on enums using the repr attribute.
From rustc --explain E0080 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
Up next
Often hit nextE0015: cannot call non-const fn in constantsA related error from the same family.Read it next →Did this answer your question?