-
Notifications
You must be signed in to change notification settings - Fork 234
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
Support for #[non_exhaustive]
enums
#1593
Comments
I don't think the issue is so much the The |
No, for public
Sure, we could newtype all the affected types. However, this would in turn mean that these newtype'd types are not compatible anymore with the original types. As we use this to implement projects that are libraries themselves, having each library expose another incompatible newtype around shared types coming from a common ancestor crate is a huge pain.
No, as stated above, this is not correct. A really simple example would be the |
This simple patch works fine:
it would probably help is we had a concrete problem to solve here - ideally via a patch to one of our fixtures so we can see exactly what the problem is and have the start of a vehicle to test any possible fixes. |
I think I understand now. There's a difference between how we handle this with UDL and with proc-macros and I keep mixing the two up. I think this should be fairly easy to fix right now, with UDL. However, the decision we make in #1865 might change that. |
UDL types can now have the `[NonExhaustive]` attribute. If present, we add a default branch arm to make things compile correctly with non-exhaustive enums. I didn't want to make this the default behavior, since in the normal case we want missing variants to result in compile errors. In theory, this also adds the `non_exhaustive` attribute for proc-macros. However, there's no way to test this because `non_exhaustive` only matters for types defined in remote crates and there's currently no proc-macro support for those.
UDL types can now have the `[NonExhaustive]` attribute. If present, we add a default branch arm to make things compile correctly with non-exhaustive enums. I didn't want to make this the default behavior, since in the normal case we want missing variants to result in compile errors. In theory, this also adds the `non_exhaustive` attribute for proc-macros. However, there's no way to test this because `non_exhaustive` only matters for types defined in remote crates and there's currently no proc-macro support for those. One slightly silly part of this is the flow of metadata. It doesn't make much sense as a metadata field, since it doesn't affect bindings generation at all. However, it needs to be because of the way that data flows from `uniffi_udl` -> `uniffi_meta` -> `uniffi_bindgen` -> `uniffi_macros`.
UDL types can now have the `[NonExhaustive]` attribute. If present, we add a default branch arm to make things compile correctly with non-exhaustive enums. I didn't want to make this the default behavior, since in the normal case we want missing variants to result in compile errors. In theory, this also adds the `non_exhaustive` attribute for proc-macros. However, there's no way to test this because `non_exhaustive` only matters for types defined in remote crates and there's currently no proc-macro support for those. One slightly silly part of this is the flow of metadata. It doesn't make much sense as a metadata field, since it doesn't affect bindings generation at all. However, it needs to be because of the way that data flows from `uniffi_udl` -> `uniffi_meta` -> `uniffi_bindgen` -> `uniffi_macros`.
UDL types can now have the `[NonExhaustive]` attribute. If present, we add a default branch arm to make things compile correctly with non-exhaustive enums. I didn't want to make this the default behavior, since in the normal case we want missing variants to result in compile errors. In theory, this also adds the `non_exhaustive` attribute for proc-macros. However, there's no way to test this because `non_exhaustive` only matters for types defined in remote crates and there's currently no proc-macro support for those. One slightly silly part of this is the flow of metadata. It doesn't make much sense as a metadata field, since it doesn't affect bindings generation at all. However, it needs to be because of the way that data flows from `uniffi_udl` -> `uniffi_meta` -> `uniffi_bindgen` -> `uniffi_macros`.
UDL types can now have the `[NonExhaustive]` attribute. If present, we add a default branch arm to make things compile correctly with non-exhaustive enums. I didn't want to make this the default behavior, since in the normal case we want missing variants to result in compile errors. In theory, this also adds the `non_exhaustive` attribute for proc-macros. However, there's no way to test this because `non_exhaustive` only matters for types defined in remote crates and there's currently no proc-macro support for those. One slightly silly part of this is the flow of metadata. It doesn't make much sense as a metadata field, since it doesn't affect bindings generation at all. However, it needs to be because of the way that data flows from `uniffi_udl` -> `uniffi_meta` -> `uniffi_bindgen` -> `uniffi_macros`.
Our code is using enums in an upstream library that are marked as
#[non_exhaustive]
. We are currently writing wrappers around these to make them work, but I'm wondering if there is interest in eventually supporting them natively in uniffi. Cheers!┆Issue is synchronized with this Jira Task
┆Issue Number: UNIFFI-282
The text was updated successfully, but these errors were encountered: