diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-21 15:18:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-21 15:18:47 -0600 |
commit | ec9852a3a8e0ee6e2b4082c1de13432bb4662f1c (patch) | |
tree | 7fb43419cad16290aea00998cc644aeff17161dd /libbindgen/src/codegen/mod.rs | |
parent | 399f590f67d3582482486939d404e9615f58ccf1 (diff) | |
parent | 5c764836380a2987da0db3997d26589e9e79d8c8 (diff) |
Auto merge of #282 - impowski:layout_template_specializations, r=emilio
First steps to fix issue #57
This should generate tests for fully specialized templates.
TODO:
- [x] Tests
r? @emilio
Diffstat (limited to 'libbindgen/src/codegen/mod.rs')
-rw-r--r-- | libbindgen/src/codegen/mod.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index c8cd4cdf..a3fefcc7 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -670,10 +670,32 @@ 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! - if self.has_non_type_template_params() || - self.is_template_specialization() { + if self.has_non_type_template_params() { + return; + } + + if self.is_template_specialization() { + let layout = item.kind().expect_type().layout(ctx); + + 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; } |