rust-num / num-derive

Procedural macros to derive numeric traits in Rust
Apache License 2.0
166 stars 24 forks source link

num-derive doesn't know how to handle newtypes with named fields yet. #59

Open zRegle opened 8 months ago

zRegle commented 8 months ago

I'm using bindgen to create a enum, here is the generated code.

#[repr(u32)]
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, FromPrimitive)]
pub enum Code {
    kSuccess = 0,
    kFailed = 1,
    kHasMore = 2,
    ... // more types
}

And I got this compile error:

#[derive(Debug, Copy, Clone, FromPrimitive)
                             ^^^^^^^^^^^^^
help: message: num-derive doesn't know how to handle newtypes with named fields yet. Please use a tuple-style nentype, or submit a PR!

num-derive version: 0.3.3

Can anyone give me some advice? Thx in advance!

cuviper commented 8 months ago

I can't reproduce the problem with that snippet alone. Are the "more types" still data-less variants?

zRegle commented 8 months ago

I can't reproduce the problem with that snippet alone. Are the "more types" still data-less variants?

Yes, the rest of the enum definition are all simple variants. BTW, it this problem could be releated to my GLIBCXX version? I can reproduce this problem on machine with GLIBCXX_3.4.28

cuviper commented 8 months ago

Are your types related to GLIBCXX? Otherwise I see no reason why GLIBCXX would affect this.

I noticed that your example code has a different derive line than the one in your error message. Are you sure that you've correctly identified which type is raising this error?