Skip to content

Commit e28cb8a

Browse files
committed
TemplateParameters.all_template_params doesn't return Option
1 parent 85b1a3a commit e28cb8a

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

src/codegen/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,8 @@ impl CodeGenerator for Var {
479479
// We can't generate bindings to static variables of templates. The
480480
// number of actual variables for a single declaration are open ended
481481
// and we don't know what instantiations do or don't exist.
482-
let type_params = item.all_template_params(ctx);
483-
if let Some(params) = type_params {
484-
if !params.is_empty() {
485-
return;
486-
}
482+
if !item.all_template_params(ctx).is_empty() {
483+
return;
487484
}
488485

489486
let ty = self.ty().to_rust_ty_or_opaque(ctx, &());
@@ -3240,11 +3237,8 @@ impl CodeGenerator for Function {
32403237
// generate bindings to template functions, because the set of
32413238
// instantiations is open ended and we have no way of knowing which
32423239
// monomorphizations actually exist.
3243-
let type_params = item.all_template_params(ctx);
3244-
if let Some(params) = type_params {
3245-
if !params.is_empty() {
3246-
return;
3247-
}
3240+
if !item.all_template_params(ctx).is_empty() {
3241+
return;
32483242
}
32493243

32503244
let name = self.name();

src/ir/comp.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1681,8 +1681,7 @@ impl Trace for CompInfo {
16811681
where
16821682
T: Tracer,
16831683
{
1684-
let params = item.all_template_params(context).unwrap_or(vec![]);
1685-
for p in params {
1684+
for p in item.all_template_params(context) {
16861685
tracer.visit_kind(p.into(), EdgeKind::TemplateParameterDefinition);
16871686
}
16881687

src/ir/template.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ use parse::ClangItemParser;
8181
/// +------+----------------------+--------------------------+------------------------+----
8282
/// |Decl. | self_template_params | num_self_template_params | all_template_parameters| ...
8383
/// +------+----------------------+--------------------------+------------------------+----
84-
/// |Foo | [T, U] | 2 | Some([T, U]) | ...
85-
/// |Bar | [V] | 1 | Some([T, U, V]) | ...
86-
/// |Inner | [] | 0 | Some([T, U]) | ...
87-
/// |Lol | [W] | 1 | Some([T, U, W]) | ...
88-
/// |Wtf | [X] | 1 | Some([T, U, X]) | ...
89-
/// |Qux | [] | 0 | None | ...
84+
/// |Foo | [T, U] | 2 | [T, U] | ...
85+
/// |Bar | [V] | 1 | [T, U, V] | ...
86+
/// |Inner | [] | 0 | [T, U] | ...
87+
/// |Lol | [W] | 1 | [T, U, W] | ...
88+
/// |Wtf | [X] | 1 | [T, U, X] | ...
89+
/// |Qux | [] | 0 | [] | ...
9090
/// +------+----------------------+--------------------------+------------------------+----
9191
///
9292
/// ----+------+-----+----------------------+
@@ -131,19 +131,14 @@ pub trait TemplateParameters {
131131
/// how we would fully reference such a member type in C++:
132132
/// `Foo<int,char>::Inner`. `Foo` *must* be instantiated with template
133133
/// arguments before we can gain access to the `Inner` member type.
134-
fn all_template_params(&self, ctx: &BindgenContext) -> Option<Vec<TypeId>>
134+
fn all_template_params(&self, ctx: &BindgenContext) -> Vec<TypeId>
135135
where
136136
Self: ItemAncestors,
137137
{
138138
let ancestors: Vec<_> = self.ancestors(ctx).collect();
139-
let all_template_params: Vec<_> = ancestors.into_iter().rev().flat_map(|id| {
139+
ancestors.into_iter().rev().flat_map(|id| {
140140
id.self_template_params(ctx).into_iter()
141-
}).collect();
142-
if all_template_params.len() > 0 {
143-
Some(all_template_params)
144-
} else {
145-
None
146-
}
141+
}).collect()
147142
}
148143

149144
/// Get only the set of template parameters that this item uses. This is a
@@ -159,14 +154,14 @@ pub trait TemplateParameters {
159154
);
160155

161156
let id = *self.as_ref();
162-
ctx.resolve_item(id).all_template_params(ctx).map(
163-
|all_params| {
164-
all_params
165-
.into_iter()
166-
.filter(|p| ctx.uses_template_parameter(id, *p))
167-
.collect()
168-
},
169-
)
157+
let all_template_params: Vec<_> = ctx.resolve_item(id).all_template_params(ctx);
158+
if all_template_params.len() > 0 {
159+
Some(all_template_params.into_iter()
160+
.filter(|p| ctx.uses_template_parameter(id, *p))
161+
.collect())
162+
} else {
163+
None
164+
}
170165
}
171166
}
172167

0 commit comments

Comments
 (0)