diff options
Diffstat (limited to 'libbindgen/src')
-rw-r--r-- | libbindgen/src/ir/item.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/libbindgen/src/ir/item.rs b/libbindgen/src/ir/item.rs index c81eab8b..1d643a45 100644 --- a/libbindgen/src/ir/item.rs +++ b/libbindgen/src/ir/item.rs @@ -688,14 +688,14 @@ impl Item { return base_name; } - if within_namespace { - return ctx.rust_mangle(&base_name).into_owned(); - } - // Concatenate this item's ancestors' names together. let mut names: Vec<_> = target.parent_id() .ancestors(ctx) .filter(|id| *id != ctx.root_module()) + .take_while(|id| { + // Stop iterating ancestors once we reach a namespace. + !within_namespace || !ctx.resolve_item(*id).is_module() + }) .map(|id| { let item = ctx.resolve_item(id); let target = ctx.resolve_item(item.name_target(ctx, false)); @@ -703,8 +703,13 @@ impl Item { }) .filter(|name| !name.is_empty()) .collect(); + names.reverse(); - names.push(base_name); + + if !base_name.is_empty() { + names.push(base_name); + } + let name = names.join("_"); ctx.rust_mangle(&name).into_owned() |