Skip to content
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

feat: support #[deprecated] on enum variants #933

Merged
merged 1 commit into from Apr 14, 2024

Conversation

bkaestner
Copy link
Contributor

@bkaestner bkaestner commented Mar 19, 2024

While the #[deprecated] attribute was already used on structs, fns and enums, it was not implemented for enum variants. The information about enum variants is already available via variant.body.annotations, so the support for the #[deprecated] attribute on enum-variant level is more or less only another pair of entries within the EnumConfig.

This commit adds two new options within the [enum] settings:

  • deprecated_variant, and
  • deprecated_variant_with_notes

Both get active only on #[deprecated] variants, e.g.,

 #[repr(u8)]
 enum ApiLevel {
     #[deprecated(note = "Legacy Support until 2025")]
     L1 = 1,
     #[deprecated]
     L2 = 2,
     L3 = 3,
     L4 = 4,
}

For enums with struct variants, the current struct deprecation methods are already working good enough (see tests/expecations/deprecated*).

This is my first PR on cbindgen, and I'm not entirely sure I correctly understood the test suite, and whether there need to be more tests for this feature.

@bkaestner bkaestner force-pushed the feature-deprecated-enum-variants branch from 4203db5 to bfe9d44 Compare March 19, 2024 22:09
While the #[deprecated] attribute was already used on structs, fns and
enums, it was not implemented for enum variants. The information about
enum variants is already available via `variant.body.annotations`, so
the support for the #[deprecated] attribute on enum-variant level is
more or less only another pair of entries within the `EnumConfig`.

This commit adds two new options within the `[enum]` settings:

- deprecated_variant, and
- deprecated_variant_with_notes

Both get active only on #[deprecated] variants, e.g.,

     #[repr(u8)]
     enum ApiLevel {
         #[deprecated(note = "Legacy Support until 2025")]
         L1 = 1,
         #[deprecated]
         L2 = 2,
         L3 = 3,
         L4 = 4,
    }

For enums with struct variants, the current struct deprecation methods
are already working good enough (see tests/expecations/deprecated*).
@bkaestner bkaestner force-pushed the feature-deprecated-enum-variants branch from bfe9d44 to be59618 Compare March 19, 2024 22:19
@emilio emilio merged commit 400f437 into mozilla:master Apr 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants