Open obi1kenobi opened 2 weeks ago
Ill take the the 2nd bullet point, a public API enum's variant had its discriminant has changed from its previous value
lint, which will cover the two bullet points you mention :)
Cool, got you marked as owning that. Are you still working on #885 as well, or is that blocked on something?
Cool, got you marked as owning that. Are you still working on #885 as well, or is that blocked on something?
Ah @dmatos2012 we actually want four lints for this issue, not two. The second bullet point describes two lints, since we want to lint for "you're breaking ABI" (such as for FFI use cases) separately from "you are breaking API." That will let us make stronger statements than "may break FFI", since hedging is generally bad when reporting errors.
Background on discriminants: https://doc.rust-lang.org/reference/items/enumerations.html#discriminants
We're looking for four lints total:
#[repr(u8)]
or#[repr(i64)]
#[repr(u8)]
or#[repr(i64)]
We distinguish between the repr/no-repr cases so that we can offer better error messages. When an enum has an explicit repr, that imposes an ABI (application binary interface) constraint in addition to the API constraint. Without a repr, the numeric value of the discriminant is fixed but its binary representation is not and could be anything.
For examples of querying the
repr
properly, please look at theenum_repr_int_changed
lint. Make sure to include test cases where the repr is#[repr(C, i64)]
or#[repr(u8, C)]
since both variants are allowed too. The lints must appropriately detect the integer repr in both these cases and more straightforward ones like#[repr(i8)]
.