summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbindgen/src/codegen/mod.rs62
-rw-r--r--libbindgen/tests/expectations/tests/anon_union.rs2
-rw-r--r--libbindgen/tests/expectations/tests/class_with_dtor.rs2
-rw-r--r--libbindgen/tests/expectations/tests/crtp.rs4
-rw-r--r--libbindgen/tests/expectations/tests/template.rs4
5 files changed, 31 insertions, 43 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index 6730a910..392ec28a 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -653,45 +653,33 @@ impl CodeGenerator for CompInfo {
// Don't output classes with template parameters that aren't types, and
// also don't output template specializations, neither total or partial.
- //
- // TODO: Generate layout tests for template specializations, yay!
-
- // TODO (imp): I will keep it like that right now and move it to function later
- if self.has_non_type_template_params() ||
- self.is_template_specialization() {
- let layout = item.kind().expect_type().layout(ctx);
- let canonical_name = item.canonical_name(ctx);
-
- if let Some(layout) = layout {
+ if self.has_non_type_template_params() {
+ return;
+ }
- let mut types = String::new();
+ if self.is_template_specialization() {
+ let layout = item.kind().expect_type().layout(ctx);
- for arg in self.template_args() {
- if let Some(name) = ctx.resolve_type(*arg).name() {
- // hope this isn't bad
- types.push_str(format!("_{}", name).as_str());
- }
- }
-
- let fn_name = format!("bindgen_test_layout_template_{}{}", canonical_name, types);
- let fn_name = ctx.rust_ident_raw(&fn_name);
- let ident = item.to_rust_ty(ctx);
- let prefix = ctx.trait_prefix();
- let size_of_expr = quote_expr!(ctx.ext_cx(),
- ::$prefix::mem::size_of::<$ident>());
- let align_of_expr = quote_expr!(ctx.ext_cx(),
- ::$prefix::mem::align_of::<$ident>());
- let size = layout.size;
- let align = layout.align;
- let item = quote_item!(ctx.ext_cx(),
- #[test]
- fn $fn_name() {
- assert_eq!($size_of_expr, $size);
- assert_eq!($align_of_expr, $align);
- }).unwrap();
- result.push(item);
- }
- return;
+ if let Some(layout) = layout {
+ let fn_name = format!("__bindgen_test_layout_template_{}", item.id().as_usize());
+ let fn_name = ctx.rust_ident_raw(&fn_name);
+ let ident = item.to_rust_ty(ctx);
+ let prefix = ctx.trait_prefix();
+ let size_of_expr = quote_expr!(ctx.ext_cx(),
+ ::$prefix::mem::size_of::<$ident>());
+ let align_of_expr = quote_expr!(ctx.ext_cx(),
+ ::$prefix::mem::align_of::<$ident>());
+ let size = layout.size;
+ let align = layout.align;
+ let item = quote_item!(ctx.ext_cx(),
+ #[test]
+ fn $fn_name() {
+ assert_eq!($size_of_expr, $size);
+ assert_eq!($align_of_expr, $align);
+ }).unwrap();
+ result.push(item);
+ }
+ return;
}
let applicable_template_args = item.applicable_template_args(ctx);
diff --git a/libbindgen/tests/expectations/tests/anon_union.rs b/libbindgen/tests/expectations/tests/anon_union.rs
index 2dc206b7..915dfbd5 100644
--- a/libbindgen/tests/expectations/tests/anon_union.rs
+++ b/libbindgen/tests/expectations/tests/anon_union.rs
@@ -76,7 +76,7 @@ impl Clone for ErrorResult {
fn clone(&self) -> Self { *self }
}
#[test]
-fn bindgen_test_layout_template_TErrorResult_int() {
+fn __bindgen_test_layout_template_17() {
assert_eq!(::std::mem::size_of::<TErrorResult<::std::os::raw::c_int>>() ,
24usize);
assert_eq!(::std::mem::align_of::<TErrorResult<::std::os::raw::c_int>>() ,
diff --git a/libbindgen/tests/expectations/tests/class_with_dtor.rs b/libbindgen/tests/expectations/tests/class_with_dtor.rs
index f09699ca..88c036b6 100644
--- a/libbindgen/tests/expectations/tests/class_with_dtor.rs
+++ b/libbindgen/tests/expectations/tests/class_with_dtor.rs
@@ -21,7 +21,7 @@ fn bindgen_test_layout_WithoutDtor() {
assert_eq!(::std::mem::align_of::<WithoutDtor>() , 8usize);
}
#[test]
-fn bindgen_test_layout_template_HandleWithDtor_int() {
+fn __bindgen_test_layout_template_11() {
assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>()
, 8usize);
assert_eq!(::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>()
diff --git a/libbindgen/tests/expectations/tests/crtp.rs b/libbindgen/tests/expectations/tests/crtp.rs
index 39629599..a50e05e4 100644
--- a/libbindgen/tests/expectations/tests/crtp.rs
+++ b/libbindgen/tests/expectations/tests/crtp.rs
@@ -24,7 +24,7 @@ impl Clone for Derived {
fn clone(&self) -> Self { *self }
}
#[test]
-fn bindgen_test_layout_template_Base() {
+fn __bindgen_test_layout_template_5() {
assert_eq!(::std::mem::size_of::<Base<Derived>>() , 1usize);
assert_eq!(::std::mem::align_of::<Base<Derived>>() , 1usize);
}
@@ -47,7 +47,7 @@ fn bindgen_test_layout_DerivedFromBaseWithDestructor() {
1usize);
}
#[test]
-fn bindgen_test_layout_template_BaseWithDestructor() {
+fn __bindgen_test_layout_template_12() {
assert_eq!(::std::mem::size_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
, 1usize);
assert_eq!(::std::mem::align_of::<BaseWithDestructor<DerivedFromBaseWithDestructor>>()
diff --git a/libbindgen/tests/expectations/tests/template.rs b/libbindgen/tests/expectations/tests/template.rs
index 970b9037..21814baa 100644
--- a/libbindgen/tests/expectations/tests/template.rs
+++ b/libbindgen/tests/expectations/tests/template.rs
@@ -13,7 +13,7 @@ pub struct Foo<T, U> {
pub _phantom_1: ::std::marker::PhantomData<U>,
}
#[test]
-fn bindgen_test_layout_template_Foo_int_int() {
+fn __bindgen_test_layout_template_10() {
assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
, 24usize);
assert_eq!(::std::mem::align_of::<Foo<::std::os::raw::c_int, ::std::os::raw::c_int>>()
@@ -176,7 +176,7 @@ pub struct TemplateWithVar<T> {
pub _phantom_0: ::std::marker::PhantomData<T>,
}
#[test]
-fn bindgen_test_layout_template_WithDtor_int() {
+fn __bindgen_test_layout_template_132() {
assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() ,
4usize);
assert_eq!(::std::mem::align_of::<WithDtor<::std::os::raw::c_int>>() ,