Skip to content

Commit 47a3a6e

Browse files
committed
fix --newtype-global-enum option
1 parent 61636e9 commit 47a3a6e

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/codegen/mod.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,24 +2814,17 @@ 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 && is_ty_named && !is_global
28182818
{
28192819
let enum_ident = ctx.rust_ident(canonical_name);
28202820
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-
};
28252821

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

src/lib.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)