Skip to content

Commit 6484e3e

Browse files
committed
ir: Test on typedefs also for template parameters that are transitively applicable before discarding them.
1 parent 98abbeb commit 6484e3e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/ir/item.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ impl Item {
167167
self.kind().expect_function()
168168
}
169169

170+
// This check is needed because even though the type might not contain the
171+
// applicable template args itself, they might apply transitively via, for
172+
// example, the parent.
173+
//
174+
// It's kind of unfortunate (in the sense that it's a sort of complex
175+
// process, but I think it gets all the cases).
176+
fn signature_contains_named_type(&self, ctx: &BindgenContext, ty: &Type) -> bool {
177+
debug_assert!(ty.is_named());
178+
self.expect_type().signature_contains_named_type(ctx, ty) ||
179+
self.applicable_template_args(ctx).iter().any(|template| {
180+
ctx.resolve_type(*template).signature_contains_named_type(ctx, ty)
181+
})
182+
}
183+
170184
pub fn applicable_template_args(&self, ctx: &BindgenContext) -> Vec<ItemId> {
171185
let ty = match *self.kind() {
172186
ItemKind::Type(ref ty) => ty,
@@ -197,7 +211,8 @@ impl Item {
197211
TypeKind::Alias(_, inner) => {
198212
let parent_args = ctx.resolve_item(self.parent_id())
199213
.applicable_template_args(ctx);
200-
let inner = ctx.resolve_type(inner);
214+
let inner = ctx.resolve_item(inner);
215+
201216
// Avoid unused type parameters, sigh.
202217
parent_args.iter().cloned().filter(|arg| {
203218
let arg = ctx.resolve_type(*arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct Wrapper<T> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<T>,
12+
}
13+
#[repr(C)]
14+
#[derive(Debug, Copy, Clone)]
15+
pub struct Wrapper_Wrapped<T> {
16+
pub t: T,
17+
}
18+
pub type Wrapper_Type<T> = Wrapper_Wrapped<T>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
template<typename T>
2+
struct Wrapper {
3+
struct Wrapped {
4+
T t;
5+
};
6+
using Type = Wrapped;
7+
};

0 commit comments

Comments
 (0)