Skip to content

Commit 475dd93

Browse files
author
bors-servo
authored
Auto merge of #613 - fitzgen:upsuper-libclang-4, r=emilio
Handle when we can't instantiate templates because we can't find a template definition #594 + my review commetn about using opaque types
2 parents ad01eb2 + 71d1100 commit 475dd93

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/ir/template.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl TemplateInstantiation {
8888
/// Parse a `TemplateInstantiation` from a clang `Type`.
8989
pub fn from_ty(ty: &clang::Type,
9090
ctx: &mut BindgenContext)
91-
-> TemplateInstantiation {
91+
-> Option<TemplateInstantiation> {
9292
use clang_sys::*;
9393

9494
let template_args = ty.template_args()
@@ -100,6 +100,10 @@ impl TemplateInstantiation {
100100
.collect()
101101
});
102102

103+
if ty.declaration().is_builtin() {
104+
return None;
105+
}
106+
103107
let definition = ty.declaration()
104108
.specialized()
105109
.or_else(|| {
@@ -124,7 +128,7 @@ impl TemplateInstantiation {
124128
let template_definition =
125129
Item::from_ty_or_ref(definition.cur_type(), definition, None, ctx);
126130

127-
TemplateInstantiation::new(template_definition, template_args)
131+
Some(TemplateInstantiation::new(template_definition, template_args))
128132
}
129133

130134
/// Does this instantiation have a vtable?

src/ir/ty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,10 @@ impl Type {
988988
(ty.template_args().is_some() &&
989989
ty_kind != CXType_Typedef) {
990990
// This is a template instantiation.
991-
let inst = TemplateInstantiation::from_ty(&ty, ctx);
992-
TypeKind::TemplateInstantiation(inst)
991+
match TemplateInstantiation::from_ty(&ty, ctx) {
992+
Some(inst) => TypeKind::TemplateInstantiation(inst),
993+
None => TypeKind::Opaque,
994+
}
993995
} else {
994996
match ty_kind {
995997
CXType_Unexposed if *ty != canonical_ty &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
pub type std_make_integer_sequence = u8;

tests/headers/builtin-template.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace std {
2+
template<class T, T... Ints>
3+
class integer_sequence;
4+
template<class T, T N>
5+
using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
6+
}

0 commit comments

Comments
 (0)