summaryrefslogtreecommitdiff
path: root/libbindgen/tests
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2016-12-29 16:47:13 -0800
committerNick Fitzgerald <fitzgen@gmail.com>2016-12-29 16:54:28 -0800
commitbc08b355b2daf10565d368a87462c6d882460e55 (patch)
treed8b64c0ed54578a4fb5003a3eb8eea04884deeca /libbindgen/tests
parentd49bae228ca346e0e1e8d49d223b1207caece543 (diff)
Do not derive Copy/Debug for some opaque types
When we treat a type as opaque, either because it is explicitly annotated as such or because it is a template that has a non-type parameter, we need to check if the size is larger than RUST_DERIVE_IN_ARRAY_LIMIT. Performing this check requires information that is up the stack, in the `Item` rather than in the `CompInfo` or `Type`. Therefore, I introduced two traits to encapsulate whether a thing can derive `Debug` and `Copy` (the `CanDeriveDebug` and `CanDeriveCopy` traits, respectively) and implemented them for ALL THE THINGS. This allowes us to perform our various checks at the level where we have access to the necessary info, and to let sub-levels do their own checks with their sub-info. Fixes #372.
Diffstat (limited to 'libbindgen/tests')
-rw-r--r--libbindgen/tests/expectations/tests/issue-372.rs63
-rw-r--r--libbindgen/tests/headers/issue-372.hpp16
2 files changed, 79 insertions, 0 deletions
diff --git a/libbindgen/tests/expectations/tests/issue-372.rs b/libbindgen/tests/expectations/tests/issue-372.rs
new file mode 100644
index 00000000..c6d9209e
--- /dev/null
+++ b/libbindgen/tests/expectations/tests/issue-372.rs
@@ -0,0 +1,63 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+pub mod root {
+ #[allow(unused_imports)]
+ use self::super::root;
+ #[repr(C)]
+ #[derive(Debug, Copy)]
+ pub struct d {
+ pub m: root::i,
+ }
+ #[test]
+ fn bindgen_test_layout_d() {
+ assert_eq!(::std::mem::size_of::<d>() , 24usize);
+ assert_eq!(::std::mem::align_of::<d>() , 8usize);
+ }
+ impl Clone for d {
+ fn clone(&self) -> Self { *self }
+ }
+ #[repr(C)]
+ #[derive(Debug, Copy)]
+ pub struct i {
+ pub j: *mut root::i,
+ pub k: *mut root::i,
+ pub l: bool,
+ }
+ #[test]
+ fn bindgen_test_layout_i() {
+ assert_eq!(::std::mem::size_of::<i>() , 24usize);
+ assert_eq!(::std::mem::align_of::<i>() , 8usize);
+ }
+ impl Clone for i {
+ fn clone(&self) -> Self { *self }
+ }
+ #[repr(u32)]
+ #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+ pub enum n {
+ o = 0,
+ p = 1,
+ q = 2,
+ r = 3,
+ s = 4,
+ t = 5,
+ b = 6,
+ ae = 7,
+ e = 8,
+ ag = 9,
+ ah = 10,
+ ai = 11,
+ }
+ #[repr(C)]
+ pub struct F {
+ pub w: [u64; 33usize],
+ }
+ #[test]
+ fn bindgen_test_layout_F() {
+ assert_eq!(::std::mem::size_of::<F>() , 264usize);
+ assert_eq!(::std::mem::align_of::<F>() , 8usize);
+ }
+}
diff --git a/libbindgen/tests/headers/issue-372.hpp b/libbindgen/tests/headers/issue-372.hpp
new file mode 100644
index 00000000..a072f061
--- /dev/null
+++ b/libbindgen/tests/headers/issue-372.hpp
@@ -0,0 +1,16 @@
+// bindgen-flags: --enable-cxx-namespaces
+template <typename a, int b> class c { a e[b]; };
+class d;
+template <typename g, g f> class C { c<d, f> h; };
+class i {
+ i *j;
+ i *k;
+ bool l;
+};
+class d {
+ i m;
+};
+enum n { o, p, q, r, s, t, b, ae, e, ag, ah, ai };
+class F {
+ C<n, ai> w;
+};