Pular para o conteúdo
TE119 · Tipos · error

Enum `@flags` precisa ser plano e não-genérico

Um enum `@flags` é genérico ou tem variante com payload. `@flags` modela uma bitmask sobre um conjunto fixo e plano de variantes unitárias — não há espaço para parâmetros de tipo ou payloads.

Why this fires

An @flags enum is generic, or has a variant that carries a payload. @flags enums represent a bitmask over a fixed, flat set of unit variants — there's no room for type parameters or per-variant payloads in that model.

@flags
enum Perm: u8 {
    Read,
    Write(int),
    //    ^^^ error[TE119]: @flags enum `Perm` requires all-unit variants;
    //        `Write` has a payload
}

Fix it

Drop the payload (and any type parameters):

@flags
enum Perm: u8 { Read, Write, Exec }   // ok — all unit variants

See also

  • TE120 — a flag value isn't a power of two or a known composite.
  • TE121 — a flag value doesn't fit the backing type.
  • TE122 — two flags occupy the same bit.
  • /docs/data-structures#enums@flags bit-flag enums.

Veja também

Buscar no Zolo

9 resultados

en