Skip to content

custom derives don't work on enums #2116

@ericseppanen

Description

@ericseppanen

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions