-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New lints: Changes to enum variant discriminants #898
Comments
Ill take the the 2nd bullet point, |
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. |
- `enum_discriminants_undefined_non_exhaustive_variant` checks for enums that gain a new non-exhaustive variant, which then causes the discriminant to become undefined. - `enum_discriminants_undefined_non_unit_variant` checks for enums that gain a new non-unit variant, which then causes the discriminant to become undefined. Resolves #898.
- `enum_discriminants_undefined_non_exhaustive_variant` checks for enums that gain a new non-exhaustive variant, which then causes the discriminant to become undefined. - `enum_discriminants_undefined_non_unit_variant` checks for enums that gain a new non-unit variant, which then causes the discriminant to become undefined. Resolves #898.
…d. (#1037) - `enum_discriminants_undefined_non_exhaustive_variant` checks for enums that gain a new non-exhaustive variant, which then causes the discriminant to become undefined. - `enum_discriminants_undefined_non_unit_variant` checks for enums that gain a new non-unit variant, which then causes the discriminant to become undefined. Resolves #898.
Background on discriminants: https://doc.rust-lang.org/reference/items/enumerations.html#discriminants
We're looking for three lints total:
repr()
has a variant that used to have a well-defined discriminant, but no longer does:repr()
" case here. This is because if the enum has arepr()
, then its variants always have a well-defined discriminant so there's nothing to lint. The case when therepr()
is removed (and therefore might un-define some discriminants) is handled by another lint.#[repr(u8)]
or#[repr(i64)]
: Add theenum_repr_variant_discriminant_changed
lint. #1036We 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)]
.The text was updated successfully, but these errors were encountered: