summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@gmail.com>2018-04-07 07:21:49 -0400
committerTamir Duberstein <tamird@gmail.com>2018-04-08 18:32:49 -0400
commite28cb8a13ecacf0dc4aeab6119ca9fea8d0a1cc9 (patch)
tree3f04a42d273a40e233284ba755a25b9aa75a5d80
parent85b1a3a9f19b57c228b4cda5915d2219e15e8533 (diff)
TemplateParameters.all_template_params doesn't return Option
-rw-r--r--src/codegen/mod.rs14
-rw-r--r--src/ir/comp.rs3
-rw-r--r--src/ir/template.rs39
3 files changed, 22 insertions, 34 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 34e87d89..e2a8b33f 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -479,11 +479,8 @@ impl CodeGenerator for Var {
// We can't generate bindings to static variables of templates. The
// number of actual variables for a single declaration are open ended
// and we don't know what instantiations do or don't exist.
- let type_params = item.all_template_params(ctx);
- if let Some(params) = type_params {
- if !params.is_empty() {
- return;
- }
+ if !item.all_template_params(ctx).is_empty() {
+ return;
}
let ty = self.ty().to_rust_ty_or_opaque(ctx, &());
@@ -3240,11 +3237,8 @@ impl CodeGenerator for Function {
// generate bindings to template functions, because the set of
// instantiations is open ended and we have no way of knowing which
// monomorphizations actually exist.
- let type_params = item.all_template_params(ctx);
- if let Some(params) = type_params {
- if !params.is_empty() {
- return;
- }
+ if !item.all_template_params(ctx).is_empty() {
+ return;
}
let name = self.name();
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 7ec2add9..8c529067 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -1681,8 +1681,7 @@ impl Trace for CompInfo {
where
T: Tracer,
{
- let params = item.all_template_params(context).unwrap_or(vec![]);
- for p in params {
+ for p in item.all_template_params(context) {
tracer.visit_kind(p.into(), EdgeKind::TemplateParameterDefinition);
}
diff --git a/src/ir/template.rs b/src/ir/template.rs
index 71164fd5..cdea85cf 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] | 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 | ...
+/// |Foo | [T, U] | 2 | [T, U] | ...
+/// |Bar | [V] | 1 | [T, U, V] | ...
+/// |Inner | [] | 0 | [T, U] | ...
+/// |Lol | [W] | 1 | [T, U, W] | ...
+/// |Wtf | [X] | 1 | [T, U, X] | ...
+/// |Qux | [] | 0 | [] | ...
/// +------+----------------------+--------------------------+------------------------+----
///
/// ----+------+-----+----------------------+
@@ -131,19 +131,14 @@ pub trait TemplateParameters {
/// how we would fully reference such a member type in C++:
/// `Foo<int,char>::Inner`. `Foo` *must* be instantiated with template
/// arguments before we can gain access to the `Inner` member type.
- fn all_template_params(&self, ctx: &BindgenContext) -> Option<Vec<TypeId>>
+ fn all_template_params(&self, ctx: &BindgenContext) -> Vec<TypeId>
where
Self: ItemAncestors,
{
let ancestors: Vec<_> = self.ancestors(ctx).collect();
- let all_template_params: Vec<_> = ancestors.into_iter().rev().flat_map(|id| {
+ ancestors.into_iter().rev().flat_map(|id| {
id.self_template_params(ctx).into_iter()
- }).collect();
- if all_template_params.len() > 0 {
- Some(all_template_params)
- } else {
- None
- }
+ }).collect()
}
/// Get only the set of template parameters that this item uses. This is a
@@ -159,14 +154,14 @@ pub trait TemplateParameters {
);
let id = *self.as_ref();
- ctx.resolve_item(id).all_template_params(ctx).map(
- |all_params| {
- all_params
- .into_iter()
- .filter(|p| ctx.uses_template_parameter(id, *p))
- .collect()
- },
- )
+ let all_template_params: Vec<_> = ctx.resolve_item(id).all_template_params(ctx);
+ if all_template_params.len() > 0 {
+ Some(all_template_params.into_iter()
+ .filter(|p| ctx.uses_template_parameter(id, *p))
+ .collect())
+ } else {
+ None
+ }
}
}