summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-01-27 05:02:18 -0800
committerGitHub <noreply@github.com>2017-01-27 05:02:18 -0800
commit33df99a73784c1846b62f97ebff3848cdd76c3b1 (patch)
treefb054a567537a5cf3f3d7f508c23ee32f21323ab
parent7bfb5a52ea3ec9099068162efc45f8e3e50c2989 (diff)
parent1bdd1a50d50d7679e02d283043a7edcd20e948a8 (diff)
Auto merge of #451 - emilio:debug-opaque-types, r=emiliov0.20.4
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.
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/codegen/mod.rs1
-rw-r--r--tests/expectations/tests/forward-declaration-autoptr.rs27
-rw-r--r--tests/expectations/tests/forward_declared_complex_types.rs3
-rw-r--r--tests/expectations/tests/same_struct_name_in_different_namespaces.rs1
-rw-r--r--tests/headers/forward-declaration-autoptr.hpp10
7 files changed, 44 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 618a02f6..007c6b14 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
[root]
name = "bindgen"
-version = "0.20.3"
+version = "0.20.4"
dependencies = [
"aster 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 085b9df8..cfb648b2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@ name = "bindgen"
readme = "README.md"
repository = "https://github.com/servo/rust-bindgen"
documentation = "https://docs.rs/bindgen"
-version = "0.20.3"
+version = "0.20.4"
build = "build.rs"
[badges]
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 3a5ae690..db17a3d1 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -775,6 +775,7 @@ impl CodeGenerator for CompInfo {
let struct_name = ctx.rust_ident_raw(&struct_name);
let tuple_struct = quote_item!(ctx.ext_cx(),
#[repr(C)]
+ #[derive(Debug, Copy, Clone)]
pub struct $struct_name([u8; 0]);
)
.unwrap();
diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs
new file mode 100644
index 00000000..31013d3a
--- /dev/null
+++ b/tests/expectations/tests/forward-declaration-autoptr.rs
@@ -0,0 +1,27 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct Foo([u8; 0]);
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct RefPtr<T> {
+ pub m_inner: *mut T,
+}
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct Bar {
+ pub m_member: RefPtr<Foo>,
+}
+#[test]
+fn bindgen_test_layout_Bar() {
+ assert_eq!(::std::mem::size_of::<Bar>() , 8usize);
+ assert_eq!(::std::mem::align_of::<Bar>() , 8usize);
+}
+impl Clone for Bar {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs
index 77849a91..119ea2b5 100644
--- a/tests/expectations/tests/forward_declared_complex_types.rs
+++ b/tests/expectations/tests/forward_declared_complex_types.rs
@@ -18,6 +18,7 @@ impl Clone for Foo_empty {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
+#[derive(Debug, Copy, Clone)]
pub struct Foo([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy)]
@@ -37,12 +38,14 @@ extern "C" {
pub fn baz_struct(f: *mut Foo);
}
#[repr(C)]
+#[derive(Debug, Copy, Clone)]
pub struct Union([u8; 0]);
extern "C" {
#[link_name = "_Z9baz_unionP5Union"]
pub fn baz_union(u: *mut Union);
}
#[repr(C)]
+#[derive(Debug, Copy, Clone)]
pub struct Quux([u8; 0]);
extern "C" {
#[link_name = "_Z9baz_classP4Quux"]
diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs
index c59e4d44..dbf93daa 100644
--- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs
+++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs
@@ -5,6 +5,7 @@
#[repr(C)]
+#[derive(Debug, Copy, Clone)]
pub struct JS_Zone([u8; 0]);
#[repr(C)]
#[derive(Debug, Copy)]
diff --git a/tests/headers/forward-declaration-autoptr.hpp b/tests/headers/forward-declaration-autoptr.hpp
new file mode 100644
index 00000000..a26c1cd2
--- /dev/null
+++ b/tests/headers/forward-declaration-autoptr.hpp
@@ -0,0 +1,10 @@
+class Foo;
+
+template <typename T>
+struct RefPtr {
+ T* m_inner;
+};
+
+struct Bar {
+ RefPtr<Foo> m_member;
+};