Skip to content

Commit 33df99a

Browse files
author
bors-servo
authored
Auto merge of #451 - emilio:debug-opaque-types, r=emilio
codegen: Derive stuff in forward declarations. So Rust is happy when you use them in template parameters, since the Derive implementations can't catch this otherwise.
2 parents 7bfb5a5 + 1bdd1a5 commit 33df99a

7 files changed

+44
-2
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "bindgen"
1313
readme = "README.md"
1414
repository = "https://github.com/servo/rust-bindgen"
1515
documentation = "https://docs.rs/bindgen"
16-
version = "0.20.3"
16+
version = "0.20.4"
1717
build = "build.rs"
1818

1919
[badges]

src/codegen/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ impl CodeGenerator for CompInfo {
775775
let struct_name = ctx.rust_ident_raw(&struct_name);
776776
let tuple_struct = quote_item!(ctx.ext_cx(),
777777
#[repr(C)]
778+
#[derive(Debug, Copy, Clone)]
778779
pub struct $struct_name([u8; 0]);
779780
)
780781
.unwrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct Foo([u8; 0]);
10+
#[repr(C)]
11+
#[derive(Debug, Copy, Clone)]
12+
pub struct RefPtr<T> {
13+
pub m_inner: *mut T,
14+
}
15+
#[repr(C)]
16+
#[derive(Debug, Copy)]
17+
pub struct Bar {
18+
pub m_member: RefPtr<Foo>,
19+
}
20+
#[test]
21+
fn bindgen_test_layout_Bar() {
22+
assert_eq!(::std::mem::size_of::<Bar>() , 8usize);
23+
assert_eq!(::std::mem::align_of::<Bar>() , 8usize);
24+
}
25+
impl Clone for Bar {
26+
fn clone(&self) -> Self { *self }
27+
}

tests/expectations/tests/forward_declared_complex_types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl Clone for Foo_empty {
1818
fn clone(&self) -> Self { *self }
1919
}
2020
#[repr(C)]
21+
#[derive(Debug, Copy, Clone)]
2122
pub struct Foo([u8; 0]);
2223
#[repr(C)]
2324
#[derive(Debug, Copy)]
@@ -37,12 +38,14 @@ extern "C" {
3738
pub fn baz_struct(f: *mut Foo);
3839
}
3940
#[repr(C)]
41+
#[derive(Debug, Copy, Clone)]
4042
pub struct Union([u8; 0]);
4143
extern "C" {
4244
#[link_name = "_Z9baz_unionP5Union"]
4345
pub fn baz_union(u: *mut Union);
4446
}
4547
#[repr(C)]
48+
#[derive(Debug, Copy, Clone)]
4649
pub struct Quux([u8; 0]);
4750
extern "C" {
4851
#[link_name = "_Z9baz_classP4Quux"]

tests/expectations/tests/same_struct_name_in_different_namespaces.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
89
pub struct JS_Zone([u8; 0]);
910
#[repr(C)]
1011
#[derive(Debug, Copy)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Foo;
2+
3+
template <typename T>
4+
struct RefPtr {
5+
T* m_inner;
6+
};
7+
8+
struct Bar {
9+
RefPtr<Foo> m_member;
10+
};

0 commit comments

Comments
 (0)