Saltar al contenido
TE115 · Tipos · error

El discriminante no cabe en el tipo de respaldo

El discriminante de una variante está fuera del rango del tipo de respaldo declarado (`enum E: u8` lo limita a `0..=255`), por lo que no sobreviviría al ida y vuelta de `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.

Véase también

Buscar en Zolo

9 resultados

en