Skip to content

Commit 0d805d7

Browse files
pvdrzkulp
authored andcommitted
fix --newtype-global-enum option
1 parent 61636e9 commit 0d805d7

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/codegen/mod.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -2814,24 +2814,19 @@ impl<'a> EnumBuilder<'a> {
28142814
is_global,
28152815
..
28162816
} => {
2817-
if ctx.options().rust_features().associated_const && is_ty_named
2817+
if ctx.options().rust_features().associated_const &&
2818+
is_ty_named &&
2819+
!is_global
28182820
{
28192821
let enum_ident = ctx.rust_ident(canonical_name);
28202822
let variant_ident = ctx.rust_ident(variant_name);
2821-
let tokens = quote! {
2822-
#doc
2823-
pub const #variant_ident : #rust_ty = #rust_ty ( #expr );
2824-
};
28252823

2826-
if is_global {
2827-
result.push(tokens);
2828-
} else {
2829-
result.push(quote! {
2830-
impl #enum_ident {
2831-
#tokens
2832-
}
2833-
});
2834-
}
2824+
result.push(quote! {
2825+
impl #enum_ident {
2826+
#doc
2827+
pub const #variant_ident : #rust_ty = #rust_ty ( #expr );
2828+
}
2829+
});
28352830
} else {
28362831
let ident = ctx.rust_ident(match mangling_prefix {
28372832
Some(prefix) => {

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl Builder {
315315
let regex_sets = &[
316316
(&self.options.bitfield_enums, "--bitfield-enum"),
317317
(&self.options.newtype_enums, "--newtype-enum"),
318+
(&self.options.newtype_global_enums, "--newtype-global-enum"),
318319
(&self.options.rustified_enums, "--rustified-enum"),
319320
(
320321
&self.options.rustified_non_exhaustive_enums,
@@ -2072,6 +2073,7 @@ impl BindgenOptions {
20722073
&mut self.constified_enums,
20732074
&mut self.constified_enum_modules,
20742075
&mut self.newtype_enums,
2076+
&mut self.newtype_global_enums,
20752077
&mut self.rustified_enums,
20762078
&mut self.rustified_non_exhaustive_enums,
20772079
&mut self.type_alias,

tests/expectations/tests/newtype-global-enum.rs

+7-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)