FromZeros doesn't support non-literal enum discriminants
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
The following is valid Rust syntax, and this type satisfies the requirements to be `FromZeros`:
```rust
#[repr(u8)]
enum Foo {
Bar = 0 + 0,
}
```
However, our `FromZeros` custom derive checks for the literal `0`, so doesn't support this. It's very unlikely to be a problem because it's almost certainly a rare if nonexistent pattern in the ecosystem.
It shouldn't be too hard to support this. In fact, it might even simplify our existing implementation. All we need to do is emit a const bound like `Enum::A as u8 == 0 || Enum::B as u8 == 0 || Enum::C as u8 == 0`. This would automatically support expressions without having to reason about them, and it would also allow us to get rid of our logic which needs to special-case both a leading variant with no explicit discriminant and a variant with an explicit `0` discriminant.
Contributor guide
Assessment
This issue has not been assessed yet.