From 7fd78ad70c0c4329206421109dc5259b7b923f7e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 15 Oct 2024 17:20:53 -0700 Subject: [PATCH] Recognize inline namespaces using clang's dedicated API for that --- .../tests/inline_namespace_macro.rs | 22 ++++++++----------- bindgen/clang.rs | 5 +++++ bindgen/ir/context.rs | 4 ++++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs index 507dd28999..99ca607d2f 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs @@ -6,19 +6,15 @@ pub mod root { pub mod repro { #[allow(unused_imports)] use self::super::super::root; - pub mod __1 { - #[allow(unused_imports)] - use self::super::super::super::root; - #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] - pub struct duration { - pub _address: u8, - } - #[allow(clippy::unnecessary_operation, clippy::identity_op)] - const _: () = { - ["Size of duration"][::std::mem::size_of::() - 1usize]; - ["Alignment of duration"][::std::mem::align_of::() - 1usize]; - }; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct duration { + pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of duration"][::std::mem::size_of::() - 1usize]; + ["Alignment of duration"][::std::mem::align_of::() - 1usize]; + }; } } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index e585fb31bd..47f07a384e 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -970,6 +970,11 @@ impl Cursor { }) } } + + /// Is this cursor's referent a namespace that is inline? + pub(crate) fn is_inline_namespace(&self) -> bool { + unsafe { clang_Cursor_isInlineNamespace(self.x) != 0 } + } } /// A struct that owns the tokenizer result from a given cursor. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 75f6a1ec8f..d32bb144a1 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2328,6 +2328,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } + if cursor.is_inline_namespace() { + kind = ModuleKind::Inline; + } + (module_name, kind) }