summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ir/context.rs63
-rw-r--r--src/ir/template.rs26
2 files changed, 39 insertions, 50 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index dbe1a64a..bbcc5698 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -1549,15 +1549,16 @@ impl BindgenContext {
.and_then(|canon_decl| {
self.get_resolved_type(&canon_decl).and_then(
|template_decl_id| {
- template_decl_id.num_self_template_params(self).map(
- |num_params| {
- (
- *canon_decl.cursor(),
- template_decl_id.into(),
- num_params,
- )
- },
- )
+ let num_params = template_decl_id.num_self_template_params(self);
+ if num_params == 0 {
+ None
+ } else {
+ Some((
+ *canon_decl.cursor(),
+ template_decl_id.into(),
+ num_params,
+ ))
+ }
},
)
})
@@ -1578,15 +1579,16 @@ impl BindgenContext {
.cloned()
})
.and_then(|template_decl| {
- template_decl.num_self_template_params(self).map(
- |num_template_params| {
- (
- *template_decl.decl(),
- template_decl.id(),
- num_template_params,
- )
- },
- )
+ let num_template_params = template_decl.num_self_template_params(self);
+ if num_template_params == 0 {
+ None
+ } else {
+ Some((
+ *template_decl.decl(),
+ template_decl.id(),
+ num_template_params,
+ ))
+ }
})
})
}
@@ -1633,17 +1635,14 @@ impl BindgenContext {
) -> Option<TypeId> {
use clang_sys;
- let num_expected_args = match self.resolve_type(template)
- .num_self_template_params(self) {
- Some(n) => n,
- None => {
- warn!(
- "Tried to instantiate a template for which we could not \
- determine any template parameters"
- );
- return None;
- }
- };
+ let num_expected_args = self.resolve_type(template).num_self_template_params(self);
+ if num_expected_args == 0 {
+ warn!(
+ "Tried to instantiate a template for which we could not \
+ determine any template parameters"
+ );
+ return None;
+ }
let mut args = vec![];
let mut found_const_arg = false;
@@ -2650,7 +2649,7 @@ impl TemplateParameters for PartialType {
vec![]
}
- fn num_self_template_params(&self, _ctx: &BindgenContext) -> Option<usize> {
+ fn num_self_template_params(&self, _ctx: &BindgenContext) -> usize {
// Wouldn't it be nice if libclang would reliably give us this
// information‽
match self.decl().kind() {
@@ -2669,9 +2668,9 @@ impl TemplateParameters for PartialType {
};
clang_sys::CXChildVisit_Continue
});
- Some(num_params)
+ num_params
}
- _ => None,
+ _ => 0,
}
}
}
diff --git a/src/ir/template.rs b/src/ir/template.rs
index b5094fc6..71164fd5 100644
--- a/src/ir/template.rs
+++ b/src/ir/template.rs
@@ -81,12 +81,12 @@ use parse::ClangItemParser;
/// +------+----------------------+--------------------------+------------------------+----
/// |Decl. | self_template_params | num_self_template_params | all_template_parameters| ...
/// +------+----------------------+--------------------------+------------------------+----
-/// |Foo | [T, U] | Some(2) | Some([T, U]) | ...
-/// |Bar | [V] | Some(1) | Some([T, U, V]) | ...
-/// |Inner | [] | None | Some([T, U]) | ...
-/// |Lol | [W] | Some(1) | Some([T, U, W]) | ...
-/// |Wtf | [X] | Some(1) | Some([T, U, X]) | ...
-/// |Qux | [] | None | None | ...
+/// |Foo | [T, U] | 2 | Some([T, U]) | ...
+/// |Bar | [V] | 1 | Some([T, U, V]) | ...
+/// |Inner | [] | 0 | Some([T, U]) | ...
+/// |Lol | [W] | 1 | Some([T, U, W]) | ...
+/// |Wtf | [X] | 1 | Some([T, U, X]) | ...
+/// |Qux | [] | 0 | None | ...
/// +------+----------------------+--------------------------+------------------------+----
///
/// ----+------+-----+----------------------+
@@ -113,18 +113,8 @@ pub trait TemplateParameters {
/// Get the number of free template parameters this template declaration
/// has.
- ///
- /// Implementations *may* return `Some` from this method when
- /// `template_params` returns `None`. This is useful when we only have
- /// partial information about the template declaration, such as when we are
- /// in the middle of parsing it.
- fn num_self_template_params(&self, ctx: &BindgenContext) -> Option<usize> {
- let len = self.self_template_params(ctx).len();
- if len > 0 {
- Some(len)
- } else {
- None
- }
+ fn num_self_template_params(&self, ctx: &BindgenContext) -> usize {
+ self.self_template_params(ctx).len()
}
/// Get the complete set of template parameters that can affect this