Skip to content

Commit b10ba43

Browse files
author
bors-servo
authored
Auto merge of #467 - emilio:template-fun-ty, r=fitzgen
ir: Don't recurse too much looking for canonical types. Fixes #405 r? @fitzgen
2 parents c1aaa6a + 63d8398 commit b10ba43

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/ir/ty.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,20 @@ impl Type {
588588

589589
let kind = match ty_kind {
590590
CXType_Unexposed if *ty != canonical_ty &&
591-
canonical_ty.kind() != CXType_Invalid => {
591+
canonical_ty.kind() != CXType_Invalid &&
592+
// Sometime clang desugars some types more than
593+
// what we need, specially with function
594+
// pointers.
595+
//
596+
// We should also try the solution of inverting
597+
// those checks instead of doing this, that is,
598+
// something like:
599+
//
600+
// CXType_Unexposed if ty.ret_type().is_some()
601+
// => { ... }
602+
//
603+
// etc.
604+
!canonical_ty.spelling().contains("type-parameter") => {
592605
debug!("Looking for canonical type: {:?}", canonical_ty);
593606
return Self::from_clang_ty(potential_id,
594607
&canonical_ty,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 Foo<T> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<T>,
12+
}
13+
pub type Foo_FunctionPtr<T> =
14+
::std::option::Option<unsafe extern "C" fn() -> T>;
15+
#[repr(C)]
16+
#[derive(Debug, Copy, Clone)]
17+
pub struct RefPtr<T> {
18+
pub _address: u8,
19+
pub _phantom_0: ::std::marker::PhantomData<T>,
20+
}
21+
#[repr(C)]
22+
#[derive(Debug, Copy, Clone)]
23+
pub struct RefPtr_Proxy<T, R, Args> {
24+
pub _address: u8,
25+
pub _phantom_0: ::std::marker::PhantomData<T>,
26+
pub _phantom_1: ::std::marker::PhantomData<R>,
27+
pub _phantom_2: ::std::marker::PhantomData<Args>,
28+
}
29+
pub type RefPtr_Proxy_member_function<R, Args> =
30+
::std::option::Option<unsafe extern "C" fn(arg1: Args) -> R>;
31+
pub type Returner<T> = ::std::option::Option<unsafe extern "C" fn() -> T>;

tests/headers/template-fun-ty.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
template <typename T>
2+
class Foo
3+
{
4+
typedef T (FunctionPtr)();
5+
};
6+
7+
template<typename T>
8+
class RefPtr {
9+
template<typename R, typename... Args>
10+
class Proxy {
11+
typedef R (T::*member_function)(Args...);
12+
};
13+
};
14+
15+
template<typename T>
16+
using Returner = T(*)();

0 commit comments

Comments
 (0)