Skip to content

Commit 1830c2d

Browse files
author
bors-servo
authored
Auto merge of #835 - emilio:tp-function, r=fitzgen
ir: We really need to traverse all edges for the used template parameter analysis to be sound. Fixes #833
2 parents 85c063b + ba9298d commit 1830c2d

File tree

4 files changed

+19
-29
lines changed

4 files changed

+19
-29
lines changed

src/ir/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'ctx, 'gen> WhitelistedItems<'ctx, 'gen>
219219
where R: IntoIterator<Item = ItemId>,
220220
{
221221
let predicate = if ctx.options().whitelist_recursively {
222-
traversal::codegen_edges
222+
traversal::all_edges
223223
} else {
224224
traversal::no_edges
225225
};

src/ir/traversal.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -201,34 +201,6 @@ pub fn all_edges(_: &BindgenContext, _: Edge) -> bool {
201201
true
202202
}
203203

204-
/// A `TraversalPredicate` implementation that only follows edges to items that
205-
/// are enabled for code generation. This lets us skip considering items for
206-
/// which we won't generate any bindings to.
207-
pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool {
208-
let cc = &ctx.options().codegen_config;
209-
match edge.kind {
210-
EdgeKind::Generic => ctx.resolve_item(edge.to).is_enabled_for_codegen(ctx),
211-
212-
// We statically know the kind of item that non-generic edges can point
213-
// to, so we don't need to actually resolve the item and check
214-
// `Item::is_enabled_for_codegen`.
215-
EdgeKind::TemplateParameterDefinition |
216-
EdgeKind::TemplateArgument |
217-
EdgeKind::TemplateDeclaration |
218-
EdgeKind::BaseMember |
219-
EdgeKind::Field |
220-
EdgeKind::InnerType |
221-
EdgeKind::FunctionReturn |
222-
EdgeKind::FunctionParameter |
223-
EdgeKind::VarType |
224-
EdgeKind::TypeReference => cc.types,
225-
EdgeKind::InnerVar => cc.vars,
226-
EdgeKind::Method => cc.methods,
227-
EdgeKind::Constructor => cc.constructors,
228-
EdgeKind::Destructor => cc.destructors,
229-
}
230-
}
231-
232204
/// A `TraversalPredicate` implementation that never follows any edges, and
233205
/// therefore traversals using this predicate will only visit the traversal's
234206
/// roots.

tests/expectations/tests/issue-833.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
#[repr(C)] pub struct nsTArray<T> { pub hdr: *const T }
7+
8+
extern "C" {
9+
pub fn func() -> *mut nsTArray<::std::os::raw::c_int>;
10+
}

tests/headers/issue-833.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// bindgen-flags: --generate functions --whitelist-function func --raw-line "#[repr(C)] pub struct nsTArray<T> { pub hdr: *const T }"
2+
3+
template<typename T>
4+
class nsTArray {
5+
T* mHeader;
6+
};
7+
8+
extern "C" nsTArray<int>* func();

0 commit comments

Comments
 (0)