Skip to content

Commit b708e07

Browse files
committed
Use bitfield getter_name in impl_partialeq
1 parent a26bf0b commit b708e07

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

src/codegen/impl_partialeq.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pub fn gen_partialeq_impl(
5151
tokens.push(gen_field(ctx, ty_item, name));
5252
}
5353
Field::Bitfields(ref bu) => for bitfield in bu.bitfields() {
54-
let name_ident = ctx.rust_ident_raw(bitfield.name());
54+
let getter_name = bitfield.getter_name();
55+
let name_ident = ctx.rust_ident_raw(getter_name);
5556
tokens.push(quote! {
5657
self.#name_ident () == other.#name_ident ()
5758
});
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Copy)]
9+
pub struct Foo {
10+
pub big_array: [::std::os::raw::c_char; 33usize],
11+
pub _bitfield_1: u8,
12+
}
13+
#[test]
14+
fn bindgen_test_layout_Foo() {
15+
assert_eq!(
16+
::std::mem::size_of::<Foo>(),
17+
34usize,
18+
concat!("Size of: ", stringify!(Foo))
19+
);
20+
assert_eq!(
21+
::std::mem::align_of::<Foo>(),
22+
1usize,
23+
concat!("Alignment of ", stringify!(Foo))
24+
);
25+
assert_eq!(
26+
unsafe { &(*(0 as *const Foo)).big_array as *const _ as usize },
27+
0usize,
28+
concat!(
29+
"Alignment of field: ",
30+
stringify!(Foo),
31+
"::",
32+
stringify!(big_array)
33+
)
34+
);
35+
}
36+
extern "C" {
37+
#[link_name = "_ZN3Foo4typeEv"]
38+
pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char;
39+
}
40+
extern "C" {
41+
#[link_name = "_ZN3Foo9set_type_Ec"]
42+
pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char);
43+
}
44+
extern "C" {
45+
#[link_name = "_ZN3Foo8set_typeEc"]
46+
pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char);
47+
}
48+
impl Clone for Foo {
49+
fn clone(&self) -> Self {
50+
*self
51+
}
52+
}
53+
impl Default for Foo {
54+
fn default() -> Self {
55+
unsafe { ::std::mem::zeroed() }
56+
}
57+
}
58+
impl ::std::cmp::PartialEq for Foo {
59+
fn eq(&self, other: &Foo) -> bool {
60+
&self.big_array[..] == &other.big_array[..]
61+
&& self.type__bindgen_bitfield() == other.type__bindgen_bitfield()
62+
}
63+
}
64+
impl Foo {
65+
#[inline]
66+
pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char {
67+
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
68+
unsafe {
69+
::std::ptr::copy_nonoverlapping(
70+
&self._bitfield_1 as *const _ as *const u8,
71+
&mut unit_field_val as *mut u8 as *mut u8,
72+
::std::mem::size_of::<u8>(),
73+
)
74+
};
75+
let mask = 7u64 as u8;
76+
let val = (unit_field_val & mask) >> 0usize;
77+
unsafe { ::std::mem::transmute(val as u8) }
78+
}
79+
#[inline]
80+
pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) {
81+
let mask = 7u64 as u8;
82+
let val = val as u8 as u8;
83+
let mut unit_field_val: u8 = unsafe { ::std::mem::uninitialized() };
84+
unsafe {
85+
::std::ptr::copy_nonoverlapping(
86+
&self._bitfield_1 as *const _ as *const u8,
87+
&mut unit_field_val as *mut u8 as *mut u8,
88+
::std::mem::size_of::<u8>(),
89+
)
90+
};
91+
unit_field_val &= !mask;
92+
unit_field_val |= (val << 0usize) & mask;
93+
unsafe {
94+
::std::ptr::copy_nonoverlapping(
95+
&unit_field_val as *const _ as *const u8,
96+
&mut self._bitfield_1 as *mut _ as *mut u8,
97+
::std::mem::size_of::<u8>(),
98+
);
99+
}
100+
}
101+
#[inline]
102+
pub fn new_bitfield_1(type__bindgen_bitfield: ::std::os::raw::c_char) -> u8 {
103+
(0 | ((type__bindgen_bitfield as u8 as u8) << 0usize) & (7u64 as u8))
104+
}
105+
#[inline]
106+
pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char {
107+
Foo_type(self)
108+
}
109+
#[inline]
110+
pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) {
111+
Foo_set_type_(self, c)
112+
}
113+
#[inline]
114+
pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) {
115+
Foo_set_type(self, c)
116+
}
117+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq
2+
3+
struct Foo {
4+
char big_array[33];
5+
char type_ : 3;
6+
char type();
7+
void set_type_(char c);
8+
void set_type(char c);
9+
};

0 commit comments

Comments
 (0)