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 derives don't work on enums #2116

Closed
ericseppanen opened this issue Nov 7, 2021 · 0 comments · Fixed by #2117
Closed

custom derives don't work on enums #2116

ericseppanen opened this issue Nov 7, 2021 · 0 comments · Fixed by #2117

Comments

@ericseppanen
Copy link
Contributor

ericseppanen commented Nov 7, 2021

@trobanga pointed out that PR #2059 (implementing #1089) doesn't seem to work if we try to add a custom derive to an enum instead of a struct.

I can see the problem if I try to extend the unit test from #2059 like this:

Input C/C++ Header

enum my_rustified_enum {
  ELEVEN = 11,
  TWELVE,
  THIRTEEN,
};
#[test]
fn test_custom_derive() {
    use std::cmp::{PartialEq, Ordering};

    let test3 = unsafe { bindings::my_rustified_enum::ELEVEN };
    let test4 = unsafe { bindings::my_rustified_enum::TWELVE };

    assert!(test3 < test4);
}

Bindgen Invocation

I tested this using cargo test within bindgen-integration/, with the custom derives specified like this:

fn add_derives(&self, name: &str) -> Vec<String> {
    if name == "my_rustified_enum" {
        vec!["PartialOrd".into()]
    } else {
        vec![]
    }
}

Actual Results

$ cargo test
   Compiling bindgen-integration v0.1.0 (.../rust-bindgen/bindgen-integration)
error[E0369]: binary operation `<` cannot be applied to type `root::my_rustified_enum`
   --> src/lib.rs:289:19
    |
289 |     assert!(test3 < test4);
    |             ----- ^ ----- root::my_rustified_enum
    |             |
    |             root::my_rustified_enum
    |
    = note: an implementation of `std::cmp::PartialOrd` might be missing for `root::my_rustified_enum`

Expected Results

PartialOrd should have been added to the #[derive(...) attribute, allowing this test to compile.

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 a pull request may close this issue.

1 participant