Skip to content

Commit 8d045d2

Browse files
author
bors-servo
authored
Auto merge of #1123 - photoszzt:fix_mangle_name, r=pepyakin
Need mangle name of fields in struct for impl debug Fix #1122 r? @fitzgen or @emilio or @pepyakin
2 parents 77046b7 + 67e98ba commit 8d045d2

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

src/codegen/impl_debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a> ImplDebug<'a> for Item {
117117
ctx: &BindgenContext,
118118
name: &str,
119119
) -> Option<(String, Vec<quote::Tokens>)> {
120-
let name_ident = ctx.rust_ident_raw(name);
120+
let name_ident = ctx.rust_ident(name);
121121

122122
// We don't know if blacklisted items `impl Debug` or not, so we can't
123123
// add them to the format string we're building up.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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, Clone)]
9+
pub struct perf_event_attr {
10+
pub type_: ::std::os::raw::c_uint,
11+
pub a: f32,
12+
pub __bindgen_anon_1: perf_event_attr__bindgen_ty_1,
13+
}
14+
#[repr(C)]
15+
#[derive(Copy, Clone)]
16+
pub union perf_event_attr__bindgen_ty_1 {
17+
pub b: ::std::os::raw::c_int,
18+
pub c: ::std::os::raw::c_int,
19+
_bindgen_union_align: u32,
20+
}
21+
#[test]
22+
fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() {
23+
assert_eq!(
24+
::std::mem::size_of::<perf_event_attr__bindgen_ty_1>(),
25+
4usize,
26+
concat!("Size of: ", stringify!(perf_event_attr__bindgen_ty_1))
27+
);
28+
assert_eq!(
29+
::std::mem::align_of::<perf_event_attr__bindgen_ty_1>(),
30+
4usize,
31+
concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1))
32+
);
33+
assert_eq!(
34+
unsafe { &(*(0 as *const perf_event_attr__bindgen_ty_1)).b as *const _ as usize },
35+
0usize,
36+
concat!(
37+
"Alignment of field: ",
38+
stringify!(perf_event_attr__bindgen_ty_1),
39+
"::",
40+
stringify!(b)
41+
)
42+
);
43+
assert_eq!(
44+
unsafe { &(*(0 as *const perf_event_attr__bindgen_ty_1)).c as *const _ as usize },
45+
0usize,
46+
concat!(
47+
"Alignment of field: ",
48+
stringify!(perf_event_attr__bindgen_ty_1),
49+
"::",
50+
stringify!(c)
51+
)
52+
);
53+
}
54+
impl Default for perf_event_attr__bindgen_ty_1 {
55+
fn default() -> Self {
56+
unsafe { ::std::mem::zeroed() }
57+
}
58+
}
59+
impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 {
60+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
61+
write!(f, "perf_event_attr__bindgen_ty_1 {{ union }}")
62+
}
63+
}
64+
#[test]
65+
fn bindgen_test_layout_perf_event_attr() {
66+
assert_eq!(
67+
::std::mem::size_of::<perf_event_attr>(),
68+
12usize,
69+
concat!("Size of: ", stringify!(perf_event_attr))
70+
);
71+
assert_eq!(
72+
::std::mem::align_of::<perf_event_attr>(),
73+
4usize,
74+
concat!("Alignment of ", stringify!(perf_event_attr))
75+
);
76+
assert_eq!(
77+
unsafe { &(*(0 as *const perf_event_attr)).type_ as *const _ as usize },
78+
0usize,
79+
concat!(
80+
"Alignment of field: ",
81+
stringify!(perf_event_attr),
82+
"::",
83+
stringify!(type_)
84+
)
85+
);
86+
assert_eq!(
87+
unsafe { &(*(0 as *const perf_event_attr)).a as *const _ as usize },
88+
4usize,
89+
concat!(
90+
"Alignment of field: ",
91+
stringify!(perf_event_attr),
92+
"::",
93+
stringify!(a)
94+
)
95+
);
96+
}
97+
impl Default for perf_event_attr {
98+
fn default() -> Self {
99+
unsafe { ::std::mem::zeroed() }
100+
}
101+
}
102+
impl ::std::fmt::Debug for perf_event_attr {
103+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
104+
write!(
105+
f,
106+
"perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}",
107+
self.type_,
108+
self.a,
109+
self.__bindgen_anon_1
110+
)
111+
}
112+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// bindgen-flags: --impl-debug
2+
struct perf_event_attr {
3+
4+
/*
5+
* Major type: hardware/software/tracepoint/etc.
6+
*/
7+
unsigned int type;
8+
9+
float a;
10+
union {
11+
int b;
12+
int c;
13+
};
14+
};

0 commit comments

Comments
 (0)