Skip to content
TE117 · Type · error

`@stable` enum requires an explicit discriminant

Under `@stable` auto-increment is disallowed: inserting a new variant in the middle would silently renumber every variant after it, breaking the encoding the annotation promises to keep.

Why this fires

An enum decorated @stable (a promise that its numeric encoding won't silently shift between versions) has a variant with no explicit = n discriminant. Under @stable, auto-increment is disallowed — inserting a new variant in the middle would otherwise renumber every variant after it without anyone noticing.

@stable
enum Packet: u8 {
    Connect = 0,
    Data,
    //   ^^^^ error[TE117]: @stable enum `Packet` requires an explicit discriminant
    //        on variant `Data` (auto-increment is not allowed under @stable)
}

Fix it

Give every variant an explicit value:

@stable
enum Packet: u8 {
    Connect = 0,
    Data    = 1,             // ok
}

See also

See also

Search Zolo

9 results

en