summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/codegen/mod.rs22
-rw-r--r--src/ir/analysis/derive_copy.rs2
-rw-r--r--src/ir/analysis/template_params.rs4
-rw-r--r--src/ir/comp.rs8
-rw-r--r--src/ir/context.rs9
-rw-r--r--src/ir/item.rs10
-rw-r--r--src/ir/template.rs40
-rw-r--r--src/ir/ty.rs8
8 files changed, 47 insertions, 56 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 6483412e..34e87d89 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3138,18 +3138,16 @@ impl TryToRustTy for TemplateInstantiation {
let def_path = def.namespace_aware_canonical_path(ctx);
ty.append_separated(def_path.into_iter().map(|p| ctx.rust_ident(p)), Term::new("::", Span::call_site()));
- let def_params = match def.self_template_params(ctx) {
- Some(params) => params,
- None => {
- // This can happen if we generated an opaque type for a partial
- // template specialization, and we've hit an instantiation of
- // that partial specialization.
- extra_assert!(
- def.is_opaque(ctx, &())
- );
- return Err(error::Error::InstantiationOfOpaqueType);
- }
- };
+ let def_params = def.self_template_params(ctx);
+ if def_params.is_empty() {
+ // This can happen if we generated an opaque type for a partial
+ // template specialization, and we've hit an instantiation of
+ // that partial specialization.
+ extra_assert!(
+ def.is_opaque(ctx, &())
+ );
+ return Err(error::Error::InstantiationOfOpaqueType);
+ }
// TODO: If the definition type is a template class/struct
// definition's member template definition, it could rely on
diff --git a/src/ir/analysis/derive_copy.rs b/src/ir/analysis/derive_copy.rs
index 69725ead..59eb469b 100644
--- a/src/ir/analysis/derive_copy.rs
+++ b/src/ir/analysis/derive_copy.rs
@@ -246,7 +246,7 @@ impl<'ctx> MonotoneFramework for CannotDeriveCopy<'ctx> {
}
// https://github.com/rust-lang/rust/issues/36640
- if info.self_template_params(self.ctx).is_some() ||
+ if !info.self_template_params(self.ctx).is_empty() ||
item.used_template_params(self.ctx).is_some()
{
trace!(
diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs
index 00504aa4..b326e6b5 100644
--- a/src/ir/analysis/template_params.rs
+++ b/src/ir/analysis/template_params.rs
@@ -275,7 +275,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> {
let decl = self.ctx.resolve_type(instantiation.template_definition());
let args = instantiation.template_arguments();
- let params = decl.self_template_params(self.ctx).unwrap_or(vec![]);
+ let params = decl.self_template_params(self.ctx);
debug_assert!(this_id != instantiation.template_definition());
let used_by_def = self.used
@@ -419,7 +419,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
// template parameters, there is a single exception:
// opaque templates. Hence the unwrap_or.
let params =
- decl.self_template_params(ctx).unwrap_or(vec![]);
+ decl.self_template_params(ctx);
for (arg, param) in args.iter().zip(params.iter()) {
let arg = arg.into_resolver()
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 8c2be498..7ec2add9 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -1669,12 +1669,8 @@ impl TemplateParameters for CompInfo {
fn self_template_params(
&self,
_ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
- if self.template_params.is_empty() {
- None
- } else {
- Some(self.template_params.clone())
- }
+ ) -> Vec<TypeId> {
+ self.template_params.clone()
}
}
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 58a90ba6..dbe1a64a 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -1366,10 +1366,7 @@ impl BindgenContext {
let mut used_params = HashMap::new();
for &id in self.whitelisted_items() {
used_params.entry(id).or_insert(
- id.self_template_params(self).map_or(
- Default::default(),
- |params| params.into_iter().map(|p| p.into()).collect(),
- ),
+ id.self_template_params(self).into_iter().map(|p| p.into()).collect()
);
}
self.used_template_parameters = Some(used_params);
@@ -2647,10 +2644,10 @@ impl TemplateParameters for PartialType {
fn self_template_params(
&self,
_ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
+ ) -> Vec<TypeId> {
// Maybe at some point we will eagerly parse named types, but for now we
// don't and this information is unavailable.
- None
+ vec![]
}
fn num_self_template_params(&self, _ctx: &BindgenContext) -> Option<usize> {
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 2b3c1b8c..1cb1d5f9 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -1112,8 +1112,8 @@ where
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
- ctx.resolve_item_fallible(*self).and_then(|item| {
+ ) -> Vec<TypeId> {
+ ctx.resolve_item_fallible(*self).map_or(vec![], |item| {
item.self_template_params(ctx)
})
}
@@ -1123,7 +1123,7 @@ impl TemplateParameters for Item {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
+ ) -> Vec<TypeId> {
self.kind.self_template_params(ctx)
}
}
@@ -1132,7 +1132,7 @@ impl TemplateParameters for ItemKind {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
+ ) -> Vec<TypeId> {
match *self {
ItemKind::Type(ref ty) => ty.self_template_params(ctx),
// If we start emitting bindings to explicitly instantiated
@@ -1140,7 +1140,7 @@ impl TemplateParameters for ItemKind {
// template params.
ItemKind::Function(_) |
ItemKind::Module(_) |
- ItemKind::Var(_) => None,
+ ItemKind::Var(_) => vec![],
}
}
}
diff --git a/src/ir/template.rs b/src/ir/template.rs
index 11a799f4..b5094fc6 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 | Some([T, U]) | Some(2) | Some([T, U]) | ...
-/// |Bar | Some([V]) | Some(1) | Some([T, U, V]) | ...
-/// |Inner | None | None | Some([T, U]) | ...
-/// |Lol | Some([W]) | Some(1) | Some([T, U, W]) | ...
-/// |Wtf | Some([X]) | Some(1) | Some([T, U, X]) | ...
-/// |Qux | None | None | None | ...
+/// |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 | ...
/// +------+----------------------+--------------------------+------------------------+----
///
/// ----+------+-----+----------------------+
@@ -109,7 +109,7 @@ pub trait TemplateParameters {
/// anything but types, so we must treat them as opaque, and avoid
/// instantiating them.
fn self_template_params(&self, ctx: &BindgenContext)
- -> Option<Vec<TypeId>>;
+ -> Vec<TypeId>;
/// Get the number of free template parameters this template declaration
/// has.
@@ -119,7 +119,12 @@ pub trait TemplateParameters {
/// 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> {
- self.self_template_params(ctx).map(|params| params.len())
+ let len = self.self_template_params(ctx).len();
+ if len > 0 {
+ Some(len)
+ } else {
+ None
+ }
}
/// Get the complete set of template parameters that can affect this
@@ -140,19 +145,14 @@ pub trait TemplateParameters {
where
Self: ItemAncestors,
{
- let each_self_params: Vec<Vec<_>> = self.ancestors(ctx)
- .filter_map(|id| id.self_template_params(ctx))
- .collect();
- if each_self_params.is_empty() {
- None
+ let ancestors: Vec<_> = self.ancestors(ctx).collect();
+ let all_template_params: Vec<_> = 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 {
- Some(
- each_self_params
- .into_iter()
- .rev()
- .flat_map(|params| params)
- .collect(),
- )
+ None
}
}
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index b42f4424..b5c78c16 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -540,7 +540,7 @@ impl TemplateParameters for Type {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
+ ) -> Vec<TypeId> {
self.kind.self_template_params(ctx)
}
}
@@ -549,13 +549,13 @@ impl TemplateParameters for TypeKind {
fn self_template_params(
&self,
ctx: &BindgenContext,
- ) -> Option<Vec<TypeId>> {
+ ) -> Vec<TypeId> {
match *self {
TypeKind::ResolvedTypeRef(id) => {
ctx.resolve_type(id).self_template_params(ctx)
}
TypeKind::Comp(ref comp) => comp.self_template_params(ctx),
- TypeKind::TemplateAlias(_, ref args) => Some(args.clone()),
+ TypeKind::TemplateAlias(_, ref args) => args.clone(),
TypeKind::Opaque |
TypeKind::TemplateInstantiation(..) |
@@ -575,7 +575,7 @@ impl TemplateParameters for TypeKind {
TypeKind::Alias(_) |
TypeKind::ObjCId |
TypeKind::ObjCSel |
- TypeKind::ObjCInterface(_) => None,
+ TypeKind::ObjCInterface(_) => vec![],
}
}
}