Skip to content

Commit 98abbeb

Browse files
committed
ir: Potential fix for bogus name aliases when combined with rust-lang#83.
1 parent 618049b commit 98abbeb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/ir/item.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,22 @@ impl Item {
248248
debug_assert!(ctx.in_codegen_phase(),
249249
"You're not supposed to call this yet");
250250
self.annotations.hide() ||
251-
ctx.hidden_by_name(&self.real_canonical_name(ctx, false))
251+
ctx.hidden_by_name(&self.real_canonical_name(ctx, false, true))
252252
}
253253

254254
pub fn is_opaque(&self, ctx: &BindgenContext) -> bool {
255255
debug_assert!(ctx.in_codegen_phase(),
256256
"You're not supposed to call this yet");
257257
self.annotations.opaque() ||
258-
ctx.opaque_by_name(&self.real_canonical_name(ctx, false))
258+
ctx.opaque_by_name(&self.real_canonical_name(ctx, false, true))
259259
}
260260

261261
/// Get the canonical name without taking into account the replaces
262262
/// annotation.
263-
fn real_canonical_name(&self, ctx: &BindgenContext, count_namespaces: bool) -> String {
263+
fn real_canonical_name(&self,
264+
ctx: &BindgenContext,
265+
count_namespaces: bool,
266+
for_name_checking: bool) -> String {
264267
let base_name = match *self.kind() {
265268
ItemKind::Type(ref ty) => {
266269
match *ty.kind() {
@@ -288,7 +291,10 @@ impl Item {
288291
// that case the referenced type is the inner alias, so
289292
// we're good there. If we wouldn't, a more complex solution
290293
// would be needed.
291-
TypeKind::TemplateAlias(..) => {
294+
TypeKind::TemplateAlias(inner, _) => {
295+
if for_name_checking {
296+
return ctx.resolve_item(inner).real_canonical_name(ctx, count_namespaces, false);
297+
}
292298
Some("")
293299
}
294300
// Else use the proper name, or fallback to a name with an
@@ -682,7 +688,7 @@ impl ItemCanonicalName for Item {
682688
if let Some(other_canon_type) = self.annotations.use_instead_of() {
683689
return other_canon_type.to_owned();
684690
}
685-
self.real_canonical_name(ctx, ctx.options().enable_cxx_namespaces)
691+
self.real_canonical_name(ctx, ctx.options().enable_cxx_namespaces, false)
686692
}
687693
}
688694

@@ -730,7 +736,7 @@ impl ItemCanonicalPath for Item {
730736
debug_assert!(is_alias, "How can this ever happen?");
731737
parent_path.pop().unwrap();
732738
}
733-
parent_path.push(self.real_canonical_name(ctx, true));
739+
parent_path.push(self.real_canonical_name(ctx, true, false));
734740

735741
parent_path
736742
}

0 commit comments

Comments
 (0)