Skip to content

Commit 7024cf6

Browse files
committed
not generate associated constants to unnamed types
1 parent 7c5b2e6 commit 7024cf6

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/codegen/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,7 @@ impl<'a> EnumBuilder<'a> {
22472247
mangling_prefix: Option<&str>,
22482248
rust_ty: quote::Tokens,
22492249
result: &mut CodegenResult<'b>,
2250+
is_ty_named: bool,
22502251
) -> Self {
22512252
let variant_name = ctx.rust_mangle(variant.name());
22522253
let expr = match variant.val() {
@@ -2279,7 +2280,7 @@ impl<'a> EnumBuilder<'a> {
22792280
}
22802281

22812282
EnumBuilder::Bitfield { canonical_name, .. } => {
2282-
if ctx.options().rust_features().associated_const {
2283+
if ctx.options().rust_features().associated_const && is_ty_named {
22832284
let enum_ident = ctx.rust_ident(canonical_name);
22842285
let variant_ident = ctx.rust_ident(variant_name);
22852286
result.push(quote! {
@@ -2634,6 +2635,7 @@ impl CodeGenerator for Enum {
26342635
constant_mangling_prefix,
26352636
enum_rust_ty.clone(),
26362637
result,
2638+
enum_ty.name().is_some(),
26372639
);
26382640
}
26392641
}
@@ -2644,6 +2646,7 @@ impl CodeGenerator for Enum {
26442646
constant_mangling_prefix,
26452647
enum_rust_ty.clone(),
26462648
result,
2649+
enum_ty.name().is_some(),
26472650
);
26482651

26492652
let variant_name = ctx.rust_ident(variant.name());

tests/expectations/tests/bitfield-enum-basic.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ impl ::std::ops::BitAndAssign for Buz {
8484
#[repr(C)]
8585
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8686
pub struct Buz(pub i8);
87-
impl _bindgen_ty_1 {
88-
pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
89-
}
90-
impl _bindgen_ty_1 {
91-
pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2);
92-
}
87+
pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
88+
pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2);
9389
impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 {
9490
type Output = Self;
9591
#[inline]
@@ -124,12 +120,8 @@ pub struct _bindgen_ty_1(pub u32);
124120
pub struct Dummy {
125121
pub _address: u8,
126122
}
127-
impl Dummy__bindgen_ty_1 {
128-
pub const DUMMY_FOO: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(1);
129-
}
130-
impl Dummy__bindgen_ty_1 {
131-
pub const DUMMY_BAR: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(2);
132-
}
123+
pub const Dummy_DUMMY_FOO: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(1);
124+
pub const Dummy_DUMMY_BAR: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(2);
133125
impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
134126
type Output = Self;
135127
#[inline]

0 commit comments

Comments
 (0)