Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ir: Properly skip inline namespaces when building names. #792

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,19 @@ impl Item {
.ancestors(ctx)
.filter(|id| *id != ctx.root_module())
.take_while(|id| {
// Stop iterating ancestors once we reach a namespace.
// Stop iterating ancestors once we reach a non-inline namespace
// when opt.within_namespaces is set.
!opt.within_namespaces || !ctx.resolve_item(*id).is_module()
})
.filter(|id| {
if !ctx.options().conservative_inline_namespaces {
if let ItemKind::Module(ref module) = *ctx.resolve_item(*id).kind() {
return !module.is_inline();
}
}

true
})
.map(|id| {
let item = ctx.resolve_item(id);
let target = ctx.resolve_item(item.name_target(ctx));
Expand Down
34 changes: 34 additions & 0 deletions tests/expectations/tests/inline_namespace_no_ns_enabled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Debug)]
pub struct std_basic_string<CharT> {
pub hider: std_basic_string_Alloc_hider,
pub length: ::std::os::raw::c_ulong,
pub __bindgen_anon_1: std_basic_string__bindgen_ty_1<CharT>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<CharT>>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_basic_string_Alloc_hider {
pub storage: *mut ::std::os::raw::c_void,
}
impl Default for std_basic_string_Alloc_hider {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Debug)]
pub struct std_basic_string__bindgen_ty_1<CharT> {
pub inline_storage: [CharT; 4usize],
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<CharT>>,
}
impl <CharT> Default for std_basic_string__bindgen_ty_1<CharT> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
impl <CharT> Default for std_basic_string<CharT> {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
18 changes: 18 additions & 0 deletions tests/headers/inline_namespace_no_ns_enabled.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// bindgen-flags: -- -std=c++11

namespace std {
inline namespace __cxx11 {

template<typename CharT>
class basic_string {
struct Alloc_hider {
void* storage;
} hider;
unsigned long length;
struct {
CharT inline_storage[4];
};
};

}
}