Skip to content

Commit

Permalink
Merge pull request #1515 from emilio/implicit-base
Browse files Browse the repository at this point in the history
codegen: Append implicit template parameters to base members.
  • Loading branch information
emilio authored Feb 4, 2019
2 parents 49b7424 + 4f17e69 commit a5ccffb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,14 +1504,15 @@ impl CodeGenerator for CompInfo {
continue;
}

let inner = base.ty.to_rust_ty_or_opaque(ctx, &());
let inner_item = ctx.resolve_item(base.ty);
let mut inner = inner_item.to_rust_ty_or_opaque(ctx, &());
inner.append_implicit_template_params(ctx, &inner_item);
let field_name = ctx.rust_ident(&base.field_name);

let base_ty = ctx.resolve_type(base.ty);
struct_layout.saw_base(base_ty);
struct_layout.saw_base(inner_item.expect_type());

fields.push(quote! {
pub #field_name : #inner ,
pub #field_name: #inner,
});
}
}
Expand Down
36 changes: 36 additions & 0 deletions tests/expectations/tests/issue-1514.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* automatically generated by rust-bindgen */

#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Thing {
pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing_Inner<T> {
pub ptr: *mut T,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
impl<T> Default for Thing_Inner<T> {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing_AnotherInner<T> {
pub _base: Thing_Inner<T>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
impl<T> Default for Thing_AnotherInner<T> {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
9 changes: 9 additions & 0 deletions tests/headers/issue-1514.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
template<typename T>
struct Thing {
struct Inner {
T *ptr;
};

struct AnotherInner : Inner {
};
};

0 comments on commit a5ccffb

Please sign in to comment.