Skip to content
TE115 · Type · error

Discriminant does not fit the backing type

A variant's discriminant is outside the declared backing type's range (`enum E: u8` limits it to `0..=255`), so it could not round-trip through `to_int()`/`from_int()`.

Why this fires

An enum variant's discriminant value doesn't fit inside the enum's declared backing type. enum E: u8 limits every discriminant to the 0..=255 range; a value outside that range can't round-trip through to_int()/from_int() on that backing type.

enum E: u8 { X = 300 }
//           ^^^^^^^ error[TE115]: discriminant 300 for `E::X` does not fit backing type `u8` (0..=255)

Fix it

1. Use a value that fits

enum E: u8 { X = 200 }          // ok — within 0..=255

2. Widen the backing type

enum E: u16 { X = 300 }         // ok — u16 covers 0..=65535

See also

  • TE114 — numeric discriminants require a non-generic, all-unit enum.
  • TE116 — duplicate discriminant value.
  • /docs/data-structures#enums — numeric enum discriminants and backing types.

See also

Search Zolo

9 results

en