-
Notifications
You must be signed in to change notification settings - Fork 694
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
Add option to generate safe and unsafe conversions for rustified enums #2908
base: main
Are you sure you want to change the base?
Conversation
@tgross35 @ojeda I could use some guidance with some of the behavior you would like to see in corner cases for this PR. Specifically I'm interested in the cases where constants that get generated even in the rustified case conflict with the constants @tgross35 requested in the issue. I have to investigate further, but I think I encountered a case with anonymous enums where this could theoretically happen. How do we want to address this? Another prefix for the constants? Something else? |
efd0708
to
e2b79ac
Compare
I guess that could be a possibility, |
#[arg(long, value_name = "REGEX")] | ||
rustified_non_exhaustive_enum: Vec<String>, | ||
/// Mark any enum whose name matches the provided regex as a Rust enum. This parameter takes | ||
/// options in the shape REGEX or REGEX=OPTIONS where OPTIONS can be a comma separated list of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this disallows a regex without options but with a =
character, right? I guess we don't need that, but just noting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. If you provide no equal sign, it uses the empty option set.
pub type Planet_ctype = ::std::os::raw::c_uint; | ||
pub const Planet_earth: Planet_ctype = 0; | ||
pub const Planet_mars: Planet_ctype = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the PR is generating the constants for (some of) the existing Rust enum
styles -- not sure if that is what others were expecting or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so are you saying that a non exhaustive rustified enum shouldn't generate constants? I'm happy to only do it if either try_from_raw
or from_raw_unchecked
is enabled.
8c41d55
to
52851c7
Compare
So I think the only CI failure remaining is the case where the generated constant for rustified enums conflicts with an existing constant already generated by bindgen in previous versions. This may be resolved by your PR revision comment of only generating constants in cases where either |
390527d
to
699f11c
Compare
It is up to the maintainers (I don't really know what they would prefer or their policies! :) -- I added that comment mainly because I was surprised by all the tests changing, i.e. I thought we were adding a new feature/mode/... that wouldn't necessarily change existing output/users. In any case, if we are hitting a case here when the constants are added, does it mean that, if you enable |
The test that is consistently failing is the |
699f11c
to
797ac8b
Compare
@jbaublitz I think I'm still leaning towards the option of putting those constants as associated constants under the |
@pvdrz I'll give it a shot. Part of the problem there is just a naming problem. For example, in most cases the variant of the enum will be named the same thing as the constant without some sort of suffix or prefix. Because they're constants it may just be sufficient to rely on the case being different if we convert all of the constants to upper case in keeping with the Rust const case convention. However, if users decide to define an enum variant as upper case, I forsee some conflicts happening. I'll try running my initial try through CI and I'll see what fails. |
Closes #2646