icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Set Explicit Discriminants for Errors and Warnings #663

Open InsertCreativityHere opened 10 months ago

InsertCreativityHere commented 10 months ago

Doing this would present 2 advantages: 1) In the implementation of these diagnostics, we always pass a stringified error code: https://github.com/icerpc/slicec/blob/fabd9d96a9872d2ca771bce3318172e17d7a4d05/src/diagnostics/errors.rs#L268 Instead of hard-coding these in, we could compute them using the discriminant. 2) Compile-time guarantee there aren't any duplicate error codes. Right now, it's up to us to make sure we don't pass the same error code for two different enums. But if we used discriminants, the Rust compiler ensures there's no duplicate values for us.