summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen/impl_partialeq.rs5
-rw-r--r--tests/expectations/tests/derive-partialeq-bitfield-same-name.rs117
-rw-r--r--tests/headers/derive-partialeq-bitfield-same-name.hpp9
3 files changed, 129 insertions, 2 deletions
diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs
index 65023e25..02783808 100644
--- a/src/codegen/impl_partialeq.rs
+++ b/src/codegen/impl_partialeq.rs
@@ -51,8 +51,9 @@ pub fn gen_partialeq_impl(
tokens.push(gen_field(ctx, ty_item, name));
}
Field::Bitfields(ref bu) => for bitfield in bu.bitfields() {
- if let Some(name) = bitfield.name() {
- let name_ident = ctx.rust_ident_raw(name);
+ if let Some(_) = bitfield.name() {
+ let getter_name = bitfield.getter_name();
+ let name_ident = ctx.rust_ident_raw(getter_name);
tokens.push(quote! {
self.#name_ident () == other.#name_ident ()
});
diff --git a/tests/expectations/tests/derive-partialeq-bitfield-same-name.rs b/tests/expectations/tests/derive-partialeq-bitfield-same-name.rs
new file mode 100644
index 00000000..9ee2db42
--- /dev/null
+++ b/tests/expectations/tests/derive-partialeq-bitfield-same-name.rs
@@ -0,0 +1,117 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+#[repr(C)]
+#[derive(Copy)]
+pub struct Foo {
+ pub big_array: [::std::os::raw::c_char; 33usize],
+ pub _bitfield_1: u8,
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(
+ ::std::mem::size_of::<Foo>(),
+ 34usize,
+ concat!("Size of: ", stringify!(Foo))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<Foo>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(Foo))
+ );
+ assert_eq!(
+ unsafe { &(*(0 as *const Foo)).big_array as *const _ as usize },
+ 0usize,
+ concat!(
+ "Alignment of field: ",
+ stringify!(Foo),
+ "::",
+ stringify!(big_array)
+ )
+ );
+}
+extern "C" {
+ #[link_name = "_ZN3Foo4typeEv"]
+ pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char;
+}
+extern "C" {
+ #[link_name = "_ZN3Foo9set_type_Ec"]
+ pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char);
+}
+extern "C" {
+ #[link_name = "_ZN3Foo8set_typeEc"]
+ pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char);
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+impl Default for Foo {
+ fn default() -> Self {
+ unsafe { ::std::mem::zeroed() }
+ }
+}
+impl ::std::cmp::PartialEq for Foo {
+ fn eq(&self, other: &Foo) -> bool {
+ &self.big_array[..] == &other.big_array[..]
+ && self.type__bindgen_bitfield() == other.type__bindgen_bitfield()
+ }
+}
+impl Foo {
+ #[inline]
+ pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char {
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ let mask = 7u64 as u8;
+ let val = (unit_field_val & mask) >> 0usize;
+ unsafe { ::std::mem::transmute(val as u8) }
+ }
+ #[inline]
+ pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) {
+ let mask = 7u64 as u8;
+ let val = val as u8 as u8;
+ let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &self._bitfield_1 as *const _ as *const u8,
+ &mut unit_field_val as *mut u8 as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ )
+ };
+ unit_field_val &= !mask;
+ unit_field_val |= (val << 0usize) & mask;
+ unsafe {
+ ::std::ptr::copy_nonoverlapping(
+ &unit_field_val as *const _ as *const u8,
+ &mut self._bitfield_1 as *mut _ as *mut u8,
+ ::std::mem::size_of::<u8>(),
+ );
+ }
+ }
+ #[inline]
+ pub fn new_bitfield_1(type__bindgen_bitfield: ::std::os::raw::c_char) -> u8 {
+ (0 | ((type__bindgen_bitfield as u8 as u8) << 0usize) & (7u64 as u8))
+ }
+ #[inline]
+ pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char {
+ Foo_type(self)
+ }
+ #[inline]
+ pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) {
+ Foo_set_type_(self, c)
+ }
+ #[inline]
+ pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) {
+ Foo_set_type(self, c)
+ }
+}
diff --git a/tests/headers/derive-partialeq-bitfield-same-name.hpp b/tests/headers/derive-partialeq-bitfield-same-name.hpp
new file mode 100644
index 00000000..a85016c7
--- /dev/null
+++ b/tests/headers/derive-partialeq-bitfield-same-name.hpp
@@ -0,0 +1,9 @@
+// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq
+
+struct Foo {
+ char big_array[33];
+ char type_ : 3;
+ char type();
+ void set_type_(char c);
+ void set_type(char c);
+};