Skip to content

Fix --newtype-global-enum option #2271

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

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2814,24 +2814,19 @@ impl<'a> EnumBuilder<'a> {
is_global,
..
} => {
if ctx.options().rust_features().associated_const && is_ty_named
if ctx.options().rust_features().associated_const &&
is_ty_named &&
!is_global
{
let enum_ident = ctx.rust_ident(canonical_name);
let variant_ident = ctx.rust_ident(variant_name);
let tokens = quote! {
#doc
pub const #variant_ident : #rust_ty = #rust_ty ( #expr );
};

if is_global {
result.push(tokens);
} else {
result.push(quote! {
impl #enum_ident {
#tokens
}
});
}
result.push(quote! {
impl #enum_ident {
#doc
pub const #variant_ident : #rust_ty = #rust_ty ( #expr );
}
});
} else {
let ident = ctx.rust_ident(match mangling_prefix {
Some(prefix) => {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ impl Builder {
let regex_sets = &[
(&self.options.bitfield_enums, "--bitfield-enum"),
(&self.options.newtype_enums, "--newtype-enum"),
(&self.options.newtype_global_enums, "--newtype-global-enum"),
(&self.options.rustified_enums, "--rustified-enum"),
(
&self.options.rustified_non_exhaustive_enums,
Expand Down Expand Up @@ -2072,6 +2073,7 @@ impl BindgenOptions {
&mut self.constified_enums,
&mut self.constified_enum_modules,
&mut self.newtype_enums,
&mut self.newtype_global_enums,
&mut self.rustified_enums,
&mut self.rustified_non_exhaustive_enums,
&mut self.type_alias,
Expand Down
12 changes: 7 additions & 5 deletions tests/expectations/tests/newtype-global-enum.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.