Rust errors / Everything else
Rust compiler error · checked with rustc 1.99.0
Rust error E0370: enum discriminant overflowed
What it meansThe maximum value of an enum was reached, so it cannot be automatically set in the next enum value.
What rustc prints
error[E0370]: enum discriminant overflowed --> main.rs:4:5 | 4 | Y, // error: enum discriminant overflowed on value after | ^ overflowed on value after 9223372036854775807 | = note: explicitly set `Y = -9223372036854775808` if that is desired outcome
Real 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
The maximum value of an enum was reached, so it cannot be automatically set in the next enum value.
Erroneous code example:
#[repr(i64)]
enum Foo {
X = 0x7fffffffffffffff,
Y, // error: enum discriminant overflowed on value after
// 9223372036854775807: i64; set explicitly via
// Y = -9223372036854775808 if that is desired outcome
}
To fix this, please set manually the next enum value or put the enum variant with the maximum value at the end of the enum. Examples:
#[repr(i64)]
enum Foo {
X = 0x7fffffffffffffff,
Y = 0, // ok!
}
Or:
#[repr(i64)]
enum Foo {
Y = 0, // ok!
X = 0x7fffffffffffffff,
}From rustc --explain E0370 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0061this function takes N arguments but M were supplied
- E0412cannot find type in this scope
- E0515cannot return reference to local variable
- E0728await is only allowed inside async functions and blocks
- E0317`if` may be missing an `else` clause
- E0320overflow while adding drop-check rules for `A<T>`
- E0436functional record update syntax requires a struct
- E0455link kind `framework` is only supported on Apple targets
Up next
Often hit nextE0061: this function takes N arguments but M were suppliedA related error from the same family.Read it next →Did this answer your question?