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.
diff --git a/Cargo.lock b/Cargo.lock
index 618a02f..007c6b1 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 085b9df..cfb648b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
 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 3a5ae69..db17a3d 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -775,6 +775,7 @@
             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 0000000..31013d3
--- /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 77849a9..119ea2b 100644
--- a/tests/expectations/tests/forward_declared_complex_types.rs
+++ b/tests/expectations/tests/forward_declared_complex_types.rs
@@ -18,6 +18,7 @@
     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 @@
     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 c59e4d4..dbf93da 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 0000000..a26c1cd
--- /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;
+};