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

Custom attribute and derive generation order #2968

Open
kriswuollett opened this issue Oct 31, 2024 · 0 comments
Open

Custom attribute and derive generation order #2968

kriswuollett opened this issue Oct 31, 2024 · 0 comments

Comments

@kriswuollett
Copy link

The interface and/or implementation of bindgen::callbacks::ParseCallbacks may need some changes to address a compile warning that may become an error in the future, see rust-lang/rust#79202. I'm guessing that the very least derives need to appear before other attributes?

I wish I remember what library it was, but I believe I already encountered a derive macro in the past that was very sensitive to order of everything and needed to be the very first one listed as well otherwise it would cause a compile error. If I come across it again, I'll be sure to update this issue.

Details

From a header file with a type like:

typedef enum {
    color_carmine_red = 0,
    color_cornflower_blue = 1,
    color_lime_green = 2,
} color_t;

Using the item_name, add_derives, add_attributes, and enum_variant_name parse callbacks:

/* automatically generated by rust-bindgen 0.70.1 */

#[repr(u32)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, strum :: AsRefStr, strum :: IntoStaticStr)]
pub enum Color {
    CarmineRed = 0,
    CornflowerBlue = 1,
    LimeGreen = 2,
}

Which causes a warning for derive helper being used before it is introduced,
rust-lang/rust#79202:

warning: derive helper attribute is used before it is introduced
 --> src/bindings.rs:6:3
  |
6 | #[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
  |   ^^^^^
7 | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, strum :: AsRefStr, strum :: IntoStaticStr)]
  |                                                   ----------------- the attribute is introduced here
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
  = note: `#[warn(legacy_derive_helpers)]` on by default

An example project is at https://github.com/kriswuollett/example-bindgen-derive-ordering/tree/0130dcd8fa3f8d0820ed53c711375152faa0cec2.

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

No branches or pull requests

1 participant