diff options
author | M Farkas-Dyck <strake888@gmail.com> | 2018-04-06 18:44:54 -0800 |
---|---|---|
committer | M Farkas-Dyck <strake888@gmail.com> | 2018-04-06 18:44:54 -0800 |
commit | 7024cf682a6ff63bbafd63a6b570826ce422e2d4 (patch) | |
tree | ffe22aa2d90a7be91ad3bdf7724db0602b97a34e | |
parent | 7c5b2e611429814eff08f0e165c5b732eac1fb02 (diff) |
not generate associated constants to unnamed types
-rw-r--r-- | src/codegen/mod.rs | 5 | ||||
-rw-r--r-- | tests/expectations/tests/bitfield-enum-basic.rs | 16 |
2 files changed, 8 insertions, 13 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 9dc555ac..f84fb701 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2247,6 +2247,7 @@ impl<'a> EnumBuilder<'a> { mangling_prefix: Option<&str>, rust_ty: quote::Tokens, result: &mut CodegenResult<'b>, + is_ty_named: bool, ) -> Self { let variant_name = ctx.rust_mangle(variant.name()); let expr = match variant.val() { @@ -2279,7 +2280,7 @@ impl<'a> EnumBuilder<'a> { } EnumBuilder::Bitfield { canonical_name, .. } => { - if ctx.options().rust_features().associated_const { + if ctx.options().rust_features().associated_const && is_ty_named { let enum_ident = ctx.rust_ident(canonical_name); let variant_ident = ctx.rust_ident(variant_name); result.push(quote! { @@ -2634,6 +2635,7 @@ impl CodeGenerator for Enum { constant_mangling_prefix, enum_rust_ty.clone(), result, + enum_ty.name().is_some(), ); } } @@ -2644,6 +2646,7 @@ impl CodeGenerator for Enum { constant_mangling_prefix, enum_rust_ty.clone(), result, + enum_ty.name().is_some(), ); let variant_name = ctx.rust_ident(variant.name()); diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index 00752b03..a8140b2e 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -84,12 +84,8 @@ impl ::std::ops::BitAndAssign for Buz { #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Buz(pub i8); -impl _bindgen_ty_1 { - pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1); -} -impl _bindgen_ty_1 { - pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2); -} +pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1); +pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2); impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 { type Output = Self; #[inline] @@ -124,12 +120,8 @@ pub struct _bindgen_ty_1(pub u32); pub struct Dummy { pub _address: u8, } -impl Dummy__bindgen_ty_1 { - pub const DUMMY_FOO: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(1); -} -impl Dummy__bindgen_ty_1 { - pub const DUMMY_BAR: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(2); -} +pub const Dummy_DUMMY_FOO: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(1); +pub const Dummy_DUMMY_BAR: Dummy__bindgen_ty_1 = Dummy__bindgen_ty_1(2); impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 { type Output = Self; #[inline] |