Input C/C++ Header
C++
template <class> class RefPtr {};
class b;
class c;
class B {
c *d;
};
class e {
typedef b a;
};
class f {
public:
f(B);
};
template <typename t> class i {
typedef T g;
RefPtr<g> h;
};
class l {
i<int> j;
};
class c {
l k;
};
class b : f {};
e Servo_Element_GetSnapshot();
</int></g></typename></class>
Bindgen Invokation
Something like:
$BINDGEN
--raw-line "#[derive(Copy)] pub struct RefPtr<t>(T);" \
--whitelist-function "Servo_.*" \
$HEADER \
-- \
--std=c++14
</t>
Actual Results
rust
/* automatically generated by rust-bindgen */
#[derive(Copy)] pub struct RefPtr<t>(T);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct b {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_b() {
assert_eq!(::std::mem::size_of::<b>() , 1usize , concat ! (
"Size of: " , stringify ! ( b ) ));
assert_eq! (::std::mem::align_of::<b>() , 1usize , concat ! (
"Alignment of " , stringify ! ( b ) ));
}
impl Clone for b {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct c {
pub k: l,
}
#[test]
fn bindgen_test_layout_c() {
assert_eq!(::std::mem::size_of::<c>() , 1usize , concat ! (
"Size of: " , stringify ! ( c ) ));
assert_eq! (::std::mem::align_of::<c>() , 1usize , concat ! (
"Alignment of " , stringify ! ( c ) ));
assert_eq! (unsafe { & ( * ( 0 as * const c ) ) . k as * const _ as usize
} , 0usize , concat ! (
"Alignment of field: " , stringify ! ( c ) , "::" , stringify
! ( k ) ));
}
impl Clone for c {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct B {
pub d: *mut c,
}
#[test]
fn bindgen_test_layout_B() {
assert_eq!(::std::mem::size_of::<b>() , 8usize , concat ! (
"Size of: " , stringify ! ( B ) ));
assert_eq! (::std::mem::align_of::<b>() , 8usize , concat ! (
"Alignment of " , stringify ! ( B ) ));
assert_eq! (unsafe { & ( * ( 0 as * const B ) ) . d as * const _ as usize
} , 0usize , concat ! (
"Alignment of field: " , stringify ! ( B ) , "::" , stringify
! ( d ) ));
}
impl Clone for B {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct e {
pub _address: u8,
}
pub type e_a = b;
#[test]
fn bindgen_test_layout_e() {
assert_eq!(::std::mem::size_of::<e>() , 1usize , concat ! (
"Size of: " , stringify ! ( e ) ));
assert_eq! (::std::mem::align_of::<e>() , 1usize , concat ! (
"Alignment of " , stringify ! ( e ) ));
}
impl Clone for e {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct f {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_f() {
assert_eq!(::std::mem::size_of::<f>() , 1usize , concat ! (
"Size of: " , stringify ! ( f ) ));
assert_eq! (::std::mem::align_of::<f>() , 1usize , concat ! (
"Alignment of " , stringify ! ( f ) ));
}
extern "C" {
#[link_name = "_ZN1fC1E1B"]
pub fn f_f(this: *mut f, arg1: B);
}
impl Clone for f {
fn clone(&self) -> Self { *self }
}
impl f {
#[inline]
pub unsafe fn new(arg1: B) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
f_f(&mut __bindgen_tmp, arg1);
__bindgen_tmp
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct i {
pub h: RefPtr<i_g>>,
}
pub type i_g<t> = T;
#[repr(C)]
#[derive(Debug, Copy)]
pub struct l {
pub j: i,
}
#[test]
fn bindgen_test_layout_l() {
assert_eq!(::std::mem::size_of::<l>() , 1usize , concat ! (
"Size of: " , stringify ! ( l ) ));
assert_eq! (::std::mem::align_of::<l>() , 1usize , concat ! (
"Alignment of " , stringify ! ( l ) ));
assert_eq! (unsafe { & ( * ( 0 as * const l ) ) . j as * const _ as usize
} , 0usize , concat ! (
"Alignment of field: " , stringify ! ( l ) , "::" , stringify
! ( j ) ));
}
impl Clone for l {
fn clone(&self) -> Self { *self }
}
extern "C" {
#[link_name = "_Z25Servo_Element_GetSnapshotv"]
pub fn Servo_Element_GetSnapshot() -> e;
}
</l></l></t></i_g></f></f></e></e></b></b></c></c></b></b></t>
Which then results in compilation errors:
$ rustc --test --crate-type lib stylo_bindings.rs
error[E0412]: cannot find type `T` in this scope
--> stylo_bindings.rs:104:23
|
104 | pub h: RefPtr<i_g>>,
| ^ did you mean `B`?
error[E0412]: cannot find type `T` in this scope
--> stylo_bindings.rs:104:23
|
104 | pub h: RefPtr<i_g>>,
| ^ did you mean `B`?
error[E0204]: the trait `Copy` may not be implemented for this type
--> stylo_bindings.rs:102:17
|
102 | #[derive(Debug, Copy, Clone)]
| ^^^^
103 | pub struct i {
104 | pub h: RefPtr<i_g>>,
| --------------------- this field does not implement `Copy`
error: aborting due to previous error
</i_g></i_g></i_g>
cc
该提问来源于开源项目:rust-lang/rust-bindgen